Basic knowledge of

selector

| this symbol represents either interpretation of the operator, namely | left and right sides of the have a match to the can

Character escaping

Escape is used to change the meaning of a character if you want to look up the/symbol through the re, but the/has a special meaning in the re. This will cause parsing errors if you write ///, so use the escape syntax /\// to match

Characters of the boundary

Character boundaries are used to control the start and end conventions for matching content

^ : Matches the beginning of the string

$: Matches the end of the string, ignoring newlines

The modifier

I: ingore case, ignore case

G: global: global matching

M: multi-line: multi-line matching

S: The default dot. Matches any character other than the newline character \n, followed by s,. Contains the newline character \n

Atomic table

Matching a metacharacter in a set of characters is done in a regular expression through the metacharacter table, which is placed in [] (square brackets).

Atomic table instructions
[] It only matches one of the atoms
(^) Matches only any atom except the character in it
[0-9] Matches any number from 0 to 9
[a-z] Matches any letter from lowercase A to z
[A-Z] Matches any letter from capital A to Z
[xyz] Matches any letter containing xyz
[^xyz] Matches any character that does not contain xyz

metacharacters

metacharacters instructions
. Matches any character except newline
\f Matches a feed character
\n Matches a newline character
\r Matches a carriage return
\d Matches a numeric character. Equivalent to [0-9]
\D Matches a non-numeric character. Equivalent to [^ 0-9]
\w Matches letters, digits, and underscores. Equivalent to [A Za – z0-9 _]
\W The value cannot contain letters, digits, or underscores. Equivalent to [^ a za – z_]
\s Matches any whitespace character, including Spaces, tabs, and page feeds. Equivalent to [\ \ n \ r \ t f \ v]
\S Matches any non-whitespace character. Equivalent to [^ \ n \ \ f \ r \ t v]
\b Match a word boundary, which is the position between words and Spaces
\B Matches non-word boundaries

All characters

You can use [\s\ s] or [\d\ d] to match all characters

Atomic groups

If you need to match more than one element at a time, you can do it through element subgroups.

The difference between an atomic group and an atomic list is that an atomic group matches more than one element at a time, whereas an atomic list matches any character

Metacharacter groups are wrapped with ()

Repeat matching

symbol instructions
{n} Repeated n times
{n,} Repeat n times or more
{n,m} Repeat n to m times
* Matches the previous expression 0 or more times. Is equivalent to, {0}
+ Matches the previous expression 1 or more times. Is equivalent to{1,}
? Matches the previous expression 0 or 1 times. Is equivalent to{0, 1}
? =n Matches any string immediately followed by the specified string n

By default, the repeat option repeats a single character, that is, not a greedy match

var str = `abbbbb`,
  reg = /ab+/i;
console.log(str.match(reg)); // ["abbbbb", index: 0, input: "abbbbb", groups: undefined]
Copy the code

After using the atomic group, the entire group is repeatedly matched

Assert that match

x(? =y) matches ‘x’ only if ‘x’ is followed by ‘y’. This is called antecedent assertion

(? <=y)x matches ‘x’ only if ‘x’ is preceded by ‘y’. This is called a trailing assertion

x(? ! Y) matches ‘x’ only if ‘x’ is not followed by ‘y’, which is called a positive negative lookup

(?

Greedy mode and non-greedy mode

When the regular expression is repeated, the default is greedy matching mode, that is, it will match as much as possible, but sometimes we do not want it to match as much as possible. Modifier to disallow duplicate matching.

symbol instructions
*? Repeat as many times as you want, but as few times as possible
+? Repeat 1 or more times, but as little as possible
?? Repeat 0 or 1 times, but as little as possible
{n,m}? Repeat n to m times, but as few as possible
{n,}? Repeat more than n times, but as little as possible