Javascript Reference
Categories: RegExp

javascript RegExp $1, ..., $9

@June 17, 2009, 6:26 p.m.
$1, ..., $9 Firefox/Netscape/NN 4 IE 4 ECMA n/a  

 

Read-only  

Parenthesized subcomponents of a regular expression return results. These results are stored individually in properties labeled 1 through 9, preceded by the $ shortcut symbol. The order is based on the position of the left parenthesis of a subcomponent: the leftmost subcomponent result is placed into $1. These properties may be used directly within parameters to String methods that use regular expressions (see the String.replace( ) method).

 
Example
 
RegExp.$2

var str="ABCD";
str = str.replace(/A(B)C(D)/g,'$1A$2C'); //BADC
 
Value

String.


Powered by Linode.