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.