AS3 js Regular Expression backreference, as3backreference

Source: Internet
Author: User

AS3 js Regular Expression backreference, as3backreference

As3 code:

Var str = ""; var reg =/(\ d {}) \/gx; // \ is a reverse grouping, representing the same matching result character of the previous grouping. For example, if \ d {} matches, \ can only be a match, var first = str. match (reg); // match (), returns an object. If reg has a global attribute g, the numeric indexes of the object are all exactly matched characters. // if no global attribute g exists, the index is the first exact match character, and other indexes are the matching characters of each group in turn for (var key in first) {trace ("first attribute name:" + key + ", value: "+ first [key])}/* output first attribute name:, value: first attribute name:, value :*/

Js Code

<Script language = "javascript"> var str = ""; var reg =/(\ d {}) \/gx; // \ indicates a reverse group, it indicates the same matching result character of the previous group. For example, if \ d {} matches, \ can only be a match, var first = str. match (reg); // match (), returns an object. If reg has a global attribute g, the numeric indexes of the object are all exactly matched characters. // if no global attribute g exists, the index is the first exact match character, and other indexes are the matching characters for (var key in first) {document. write ("first attribute name:" + key + ", value:" + first [key])} </script> <! -- Output. First time attribute name:, value: first time attribute name:, value: -->

More complex reverse references:

The following is a simple regular expression for keyword search highlighted ..

AS3

Var str = ""; var reg =/(\ d {}) \/gx; var first = str. replace (reg, "<font color = red >$ $ </font> "); // output <font color = red >$ </font>. // Replace () is used to replace the matched string with the corresponding field. // Note: $ reverse represents the group \ d {} in the first bracket of reg, and $ is directly displayed, indicating that the regular expression only recognizes the group as the group, do not recognize/as the second group trace (first );

JS

<Script language = "javascript"> var str = ""; var reg =/(\ d {}) \/gx; var first = str. replace (reg, "<font color = red >$ $ </font> "); // output <font color = red >$ </font>. // Replace () is used to replace the matched string with the corresponding field. // Note: $ reverse represents the group \ d {} in the first bracket of reg, and $ is directly displayed, indicating that the regular expression only recognizes the group as the group, does not recognize/as the second group document. write (first); </script>

The above content is the reverse reference of AS3 js regular expression introduced by Alibaba Cloud. I hope it will be helpful to you!

Articles you may be interested in:
  • Example of reverse expression reference in javascript
  • Detailed description of grouping and reverse reference of JavaScript Regular Expressions

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.