I. character classes
Concept:Put the Individual Direct character in square brackets to form a character class ).
Note:Red indicates that it is not particularly clear
[...] -- Indicates that any character in the character class meets
[^...] -- Except for any character in the character class
. -- Any character except the linefeed (\ n) and Unicode terminator (I do not know what to use ?)
\ W -- (Word) any ASCII single character, = [a-zA-Z0-9]
\ W -- any non-ASCII single-character, = [^ a-zA-Z0-9]
\ S -- (Space) Any Unicode white space characters
\ S -- any non-Unicode white space characters
\ D -- any ASCII number, equivalent to [0-9]
\ D -- except ASCII numbers, = [^ 0-9]
[\ B] -- returns the amount directly (I don't know what it is ?)
Ii. Repetition
There are also {n, m}, {n ,}, {n },?, +, * Not explained one by one
Note: duplicate copies match one or more copies of the previous mode.
3. Non-Greedy repetition (I can understand it, but I cannot understand it after the experiment !)
CopyCode The Code is as follows: var S = "aaaaabab ";
VaR tanlan =/a * B /;
VaR landu =/*? B /;
VaR T = S. Match (tanlan); // thought t: aaaaabab, L: aaaaaaab
VaR L = S. Match (landu); // The two matched arrays are actually the same.
4. Selection, grouping, and reference
|: Select
The expression that matches the symbol from left to right (it will not go back after matching one)
VaR regchoose =/\ D {2} | \ W {4}/; // either two decimal places or four lower-case letters. matching the first one does not match the second one.
(): Combination
Role 1: merge a separate project group into a subexpression
VaR regcombination =/(cainiao eats insects) + insects eats vegetables // "cainiao eats insects" must appear once or more times
Role 2: retrieve the string and match it later