Regexp.$1-$9

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.