JavaScript RegExp. $1...$9 attribute Detailed __java

Source: Internet
Author: User

The Regexp.$1...$9 property is used to return text that matches a subexpression in the regular expression pattern. A group that resembles the match method in C #.

A partial expression within each parenthesis in a regular expression is a subexpression.

This property is a read-only property of the RegExp global object, which is supported by all major browsers. Grammar

RegExp. $n

The value of n is between [1, 9], which represents the textual content of the nth subexpression. For example, regexp.$1 represents the textual content that the first subexpression matches. return value

The value of the Regexp.$1...$9 property is a string that returns the text matched by the nth subexpression in the last regular expression match.

Although the parentheses in the regular expression pattern can have any number of them, this property saves only the first 9 matching text.

Note: The REGEXP here is a global object, and Regexp.$1...$9 is a global property. When performing any regular expression matching operation, JavaScript automatically updates the global properties on the global object RegExp to store the matching results for this regular expression pattern. When a regular expression match is executed again, the global properties on the regexp are updated to overwrite the previous stored data to reflect the matching result of this regular expression pattern. Example & Description

var str = "x98y87z65";//three digit part with parentheses, representing the subexpression var reg =/^x (\d+) Y (\d+) Z (\d+) $/; reg.test (str); The matching method of other regular expressions such as exec () can also be used, the same as Document.writeln (regexp.$1); Document.writeln (regexp.$2); Document.writeln (regexp.$3);
<a str = ' href= ' http://www.365mini.com/"title=" Home "target=" _blank ">CodePlayer</a>";
Extract URL reg =/<a\s[^>]*href= "([^" >]+) "[^>]*>/;
Reg.exec (str); Document.writeln (regexp.$1); http://www.365mini.com/

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.