Non-standard 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, the $ property is a static and read-only property that contains a regular expression that matches a substring of parentheses. This feature is non-standard, try not to use it in a production environment. Grammar
Regexp.$1
Regexp.$2
Regexp.$3
Regexp.$4
Regexp.$5
Regexp.$6
Regexp.$7
Regexp.$8
regexp.$9 Description
1,..., 1, ..., 9 properties are static, and he is not an independent regular expression property. So we always use them like this regexp. 1,..., RegExp. 1, ..., regexp.9.
The value of the property is read-only and will change only if it matches correctly.
The parentheses match is infinite, but the RegExp object can capture only nine. You can get all the bracket matches by returning an array index.
These properties can replace strings in the String.Replace method. In this case, you don't need to add regexp to the front. The following examples are described in detail. When the regular expression does not contain parentheses, the $n ' s in the script is literally meant (when n is a positive integer). Example The application of $n in String.Replace
The following script uses the Replace () method to match a namestring instance of the previous format to output the last-one format. In the replacement text, the script uses 1 and 1 and 2 to indicate the result of the parentheses in the regular expression.
var re =/(\w+) \s (\w+)/;
var str = ' John Smith ';
Str.replace (Re, ' $, $ '); "Smith, John"
regexp.$1;//"John"
regexp.$2;//"Smith"
Browser Fit
Desktop
Feature |
Chrome |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari |
Basic Support |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
Mobile
Feature |
Android |
Chrome for Android |
Firefox Mobile (Gecko) |
IE Mobile |
Opera Mobile |
Safari Mobile |
Basic Support |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n