Grammar
Metacharacters: (pattern) function: grouping for repeated matches
Attribute $1~$9 If it exists, it is used to get the substring matched in the corresponding packet
1 or to match the contents of the first group
2 or $ is used to match the contents of the first group
...
9 or $ is used to match the contents of the first group
Usage examples
1 2 3 4 5 6 |
var reg =/(A +) (b| c| D) +) (e+)/gi;//The regular expression has 4 groupings//Correspondence//regexp.$1 <-> (A +)//regexp.$2 <-> (b| c| D) +//regexp.$3 <-> (b| c| D)//regexp.$4 <-> (e+) |
The code above also gives the use of $1~$9
$1~$9 is a predefined static property of a regular expression, referenced by regexp.$1
Grouping nested Relationship Description
The preceding code can also describe nested relationships for grouping
1 2 3 4 5 6 7 8 9 |
Test environment Chrome browser var str = "ABCDE"; var reg =/(A +) (b| c| D) +) (e+)/gi; Str.match (reg);//output: ["ABCDE"] reg.exec (str, ' I ');//output: ["ABCDE", "A", "BCD", "D", "E"] regexp.$1;//output: "A" regexp.$2;// Output: "BCD" regexp.$3;//output: "D" regexp.$4;//output: "E" |
This makes it clear that the nested relationships of the grouped
In summary: When there are small groupings in large groupings, small groupings are grouped behind the large group, and so on