JavaScript Regular Expressions support packet capture, and the results of grouping are stored in the static property $1-$9 of RegExp. That is, when the number of groups in a regular expression exceeds 9, the regexp retains a maximum of 9.
Regular Var with 10 groupings RegExp =/(\w)-(\w)-(\w)-(\w)-(\w)-(\w)-(\w)-(\w)-(\w)-(\w)/;var str = ' A-b-c-d-e-f-g-h-i-j-k-l-m-n-o ';//regexp.test (str); regexp.exec (str); for (Var i=1;i<=10;i++) {Console.log (regexp ["$" +i]);}
1.The $, ..., $9 properties is static, there is not a property of an individual regular expression object. Instead, them as regexp.$1, ..., regexp.$9.
2.The values of these properties are read-only and modified whenever successful matches is made.
var re =/(\w)-(\w)-(\w)-(\w)-(\w)-(\w)-(\w)-(\w)-(\w)-(\w)/;var str1 = ' a-b-c-d-e-f-g-h-i-j '; var str2 = ' Z-y-x-t-s-r-q-p-o-n '; re.test (str1); for (Var i=1;i<=10;i++) {Console.log (regexp["$" +i]);} Match failed, $1-$9 invariant re.test ("A-b-c"), for (Var i=1;i<=10;i++) {Console.log (regexp["$" +i]);} Match succeeded, $1-$9 change re.test (STR2); for (Var i=1;i<=10;i++) {Console.log (regexp["$" +i]);}
can refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n
The $1-$9 of the static properties of the JavaScript regular expression regexp