Differences between regular expression creation methods and simple regular expression compiling methods (js learning summary), regular expression js
In the literal mode, all the content we wrap between them are metacharacters, and some have special meanings. Most of them are common metacharacters that represent their meanings.
var name = 'wo'; var reg = /^\d+"+name+"\d+$/
To solve the above requirement of adding a variable to the regular expression, we can only use the instance creation method.
var reg = new RegExp("^\\d+"+name+"\\d+$","g")
What is the difference between the literal mode and the instance Creation Mode in regular expressions?
1. Everything that appears in the literal mode is metacharacters. Therefore, you cannot splice variable values, but you can create an instance.
2. Write \ d directly in the literal, and translate it into \ d in the instance.
Exercise regular expression:
1. Age between 18-65 // age between 18-19 20-59 60-65
var reg = /^(1[8,9] | [2,5]\d | 6[0,5])$/
2. Verify the email address Regular Expression (Lite version)
Rules on the left side of the mailbox: numbers, letters, underscores, periods, and ,.,-
var reg = /^[\w.-]+@[0-9a-zA-Z]+(\.[a-zA-Z]{2,4}){1,2}$/
3. The Chinese standard real name contains 2-4 Chinese Characters
var reg = /^[\u4e00-\u9fa5]{2,4}$/
4. ID card number
var reg = /^\d{17}(\d | x)$/ var reg = /^\(d{2})(\d{4})(\d{4})(\d{2})(\d{2})(\d{2})(\d)(\d | X)$/
The above section describes the differences between creating regular expressions and writing simple regular expressions (js learning summary). I hope this will help you, if you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!