RegExp Object

An intrinsic global object that stores information about the results of regular expression pattern matches. This object cannot be constructed explicitly.

Properties

RegExp Object Properties

Methods

The RegExp object has no methods.

Requirements

Version 3

Remarks

The RegExp object cannot be created directly, but it is always available. Until a successful regular expression search has been completed, the initial values of the various properties of the RegExp object are as follows:

Property

Shorthand

Initial Value

index

 

-1

input

$_

Empty string

lastIndex

 

-1

lastMatch

$&

Empty string.

lastParen

$+

Empty string.

leftContext

$`

Empty string.

rightContext

$'

Empty string.

$1 - $9

 

Empty string.

The global RegExp object should not be confused with the Regular Expression object. Although they sound similar, they are separate and distinct. The properties of the global RegExp object contain continually updated information about each match as it occurs, while the properties of the Regular Expression object contain only information about the matches that occur with a single instance of the Regular Expression.

Note

The properties of RegExp 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 global RegExp object. This example must be compiled with the /fast- option.

Example

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

The output from this code is:

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

See Also

Concepts

Regular Expression Syntax

Reference

Regular Expression Object

String Object

/fast