How to create
var reg=/\s/var reg=New RegExp ('\\s')//need to be escaped
Matching principle
All letters and numbers are matched by literal means
Special symbols need to be escaped with a backslash (\) as a prefix
Match character
[...] Match any of the characters in parentheses
[^...] ^ as the first character in the left parenthesis, for example: [^ABC] means all characters except A,b,c
\w equivalent to [a-za-z0-9] \w equivalent to [^a-za-z0-9]
\s any Unicode whitespace character \s non-whitespace
\d any ASCII number, equivalent to [0-9] \d takes a character other than 0-9
[\b] backspace direct volume
Multiple matches
{N,m} matches the number of occurrences of the previous item , greater than or equal to n, less than or equal to M
{n} matches n times
{N,} matches at least n times
? Equivalent to {0,1}
+ equivalent to {1,}
* Equivalent to {0,}
Specify a matching location
^ Start of matching string
$ match End of string
\s matches the word boundary, \s the opposite, for example:
The (? =p) 0 wide forward assertion requires that the next characters all match p (?! p) on the contrary
Modifier
At the end/outside
I pattern matching is case insensitive
G Global Match
M multi-line pattern matching, example:
Select, sublet, quote
| Select modifier, match left to right by expression, match to left, right mismatch
(...) combinations, combining several items into 1 units, which can be referenced by \ n (?...) Group only, do not participate in references, can refer to return results
\ n used to refer to the previous (... ) matches
Regular expressions in JavaScript