Use parentheses "()" to group, so that sub-expressions (sub-patterns) can be decorated as a whole, the results of sub-expressions matching are recorded and can be accessed separately.
/(A (b (CD) {2}) +) ef/
The references correspond to each other:
\1 Correspondence (A (b (CD) {2}) +)
\2 Correspondence (b (CD) {2})
\3 Correspondence (CD)
str = "Pic1.gif gif2.gif pic.gif";
Reg =/(. +) ([1-4]) \.\1/;
Arr_m = Str.match (reg);//arr_m = ["Gif2.gif", "gif", "2"]
Parse: (. +) Match gif
([1-4]) matches a number between 1~4
\. Immediately following "."
\1 referencing the first sub-expression
str = "numA2 numa2numb3c4c4 numd5e6e6numd5e6d5";
reg =/(num ([a-z][0-9]) {2}) \2+/g;
Arr_m = Str.match (reg);//arr_m = ["Numb3c4c4", "Numd5e6e6"];
str = "Happy is the Selection";
Reg =/(^\w+) \b (. *) \b (\w+$)/;
Arr_m = Str.match (reg);
STR2 = Str.replace (Reg,)
JavaScript Regular expression-reverse reference