The regular exec method returns what value groups is used to store in the array?


var str = "ac123abc456abc";
var result = reg.exec (str);
console.log (result);
/ / = > result: ["123", index: 2, input: "ac123abc456abc", groups: undefined]
/ / = > what is the function of groups?


groups is a new field , which is used to store information about named capture groups:

 

change reg in your example to / (\ d +) / the part enclosed in parentheses is called "capture", and the corresponding English is group. The group in the result in
exec is used to enumerate the capture of "names and names".

change reg to / (? < test >\ d+) / , where ? < test > means that the captured "name" is test,. If you execute it, you will see that there is an extra attribute named test in result.groups, where the corresponding value is \ d + matching text.

Menu