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