Export (0) Print
Expand All

$1...$9 Properties 

Returns the nine most-recently memorized portions found during pattern matching. Read-only.


RegExp.$n 

RegExp

Required. The global RegExp object.

n

Required. An integer from 1 through 9.

The value of the $1...$9 properties is modified whenever a successful parenthesized match is made. Any number of parenthesized substrings may be specified in a regular expression pattern, but only the nine most recent can be stored.

NoteNote

The properties of the RegExp object are not available when running in fast mode, the default for JScript. To compile a program from the command line that uses these properties, you must turn off the fast option by using /fast-. It is not safe to turn off the fast option in ASP.NET because of threading issues.

The following example illustrates the use of the $1...$9 properties:

var s : String;
var re : RegExp = new RegExp("d(b+)(d)","ig");
var str : String = "cdbBdbsbdbdz";
var arr : Array = re.exec(str);
s = "$1 contains: " + RegExp.$1 + "\n";
s += "$2 contains: " + RegExp.$2 + "\n";
s += "$3 contains: " + RegExp.$3;
print(s);

After compiling with the /fast- option, the output of this program is:

$1 contains: bB
$2 contains: d
$3 contains:

Community Additions

ADD
Show:
© 2015 Microsoft