Home >Web Front-end >JS Tutorial >Js regular expression knowledge summary_javascript skills
Regular expression:
1. What is RegExp? RegExp is the abbreviation of regular expression. RegExp objects are used to specify the content to be retrieved from text.
2. Define RegExp: var variable name=new RegExp();
3. The RegExp object has 3 methods:
1) test() retrieves the specified value in the string, and the return value is true or false.
2) exec()
3) compile()
4. Modifier
1) i performs case-insensitive matching
2) g performs global matching
3) m performs multi-line matching
5. Square brackets (used to find characters within a certain range)
1) [abc] Find any characters between square brackets
2) [^abc] finds any characters not between square brackets
3) [0-9] Find any number between 0-9
4) [a-z] Find any lowercase character between a-z
5) [A-Z] Find any uppercase character between A-Z
6) [A-z] Find any character between uppercase A-lowercase z
7) [adgk] Find any character within the given set
8) [^adgk] Find any character outside the given set
9) (red|biue|green) Find any given option
6. Metacharacters
1) w: Find word characters
2) W: Find non-word characters
3) d: Find numbers
4) D: Find non-numeric characters
7. Quantifier
n matches any string containing at least one n.
n* matches any string containing zero or more n.
n? matches any string containing zero or one n.
n{X} matches a string containing X sequences of n.
n{X,Y} matches a string containing X or Y sequences of n.
n{X,} matches a string containing at least X sequences of n.
n$ matches any string ending in n.
^n matches any string starting with n.
?=n matches any string immediately followed by the specified string n.
?!n matches any string that is not immediately followed by the specified string n.
[Exercise 1] Determine whether the format of the entered ID card is correct