AS3 JS Regular Expression Reverse reference (backreference) _ Regular expression

Source: Internet
Author: User
Tags numeric regular expression

AS3 Code:

var str = ""; 
var reg =/(\d{}) \/gx; 
\ is a reverse grouping that represents the same matching result character as the previous group. such as \d{} match, then \ can only be matched, 
var first=str.match (reg); 
Match (), returns an object, if Reg has global attribute G, the object's numeric index is the exact match character, 
//If there is no global attribute G, the index is the first exact match character, and the other indexes are matched characters for each group for 
{ 
Trace (first property name: "+key +", Value: "+ First[key]) 
}/ 
* 
output 
First property name:, Value: 
First property name:, Value: 
*/

JS Code

<script language= "JavaScript" > 
var str = ""; 
var reg =/(\d{}) \/gx; 
\ is a reverse grouping that represents the same matching result character as the previous group. such as \d{} match, then \ can only be matched, 
var first=str.match (reg); 
Match (), returns an object, if Reg has global attribute G, the object's numeric index is the exact match character, 
//If there is no global attribute G, the index is the first exact match character, and the other indexes are matched characters for each group in order 
(Var key in First) 
{ 
document.write ("+key +", Value: "+ First[key]") 
} 
</script> 
<!-- 
output.
First property name:, Value: 
First property name:, Value: 

More complex reverse references:

Here is a simple keyword search highlighting regular expression usage.

AS3

var str = ""; 
var reg =/(\d{}) \/gx; 
var first=str.replace (Reg, "<font color=red>$$</font>"); 
Output <font Color=red>$</font><font color=red>$</font>. The 
//replace () function is to replace the matching string with the corresponding field. 
//Note the $ reverse represents the group \d{} in the first bracket of Reg, and the $ is shown directly, indicating that the regular expression only recognizes parentheses as grouping and does not recognize/identify as the second group 

Js

<script language= "JavaScript" > 
var str = ""; 
var reg =/(\d{}) \/gx; 
var first=str.replace (Reg, "<font color=red>$$</font>"); 
Output <font Color=red>$</font><font color=red>$</font>. The 
//replace () function is to replace the matching string with the corresponding field. 
//Note the $ reverse represents the group \d{} in the first bracket of Reg, and the $ is shown directly, indicating that the regular expression only recognizes parentheses as a grouping and does not recognize/identify as the second grouping 
document.write (a); 

The above content is small to introduce the AS3 JS regular expression of the reverse reference (backreference), I hope to help you!

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.