RegExp Object (JavaScript)

An intrinsic global object that stores information about the results of regular expression pattern matches.

Syntax


RegExp.property   

Remarks

The required property argument can be any one of the RegExp object properties.

The RegExp object cannot be created directly, but is always available for use. 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 $1 - $9 Empty string.

Its properties have undefined as their value until a successful regular expression search has been completed.

The global RegExp object should not be confused with the Regular Expression object. Even though they sound like the same thing, 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 that instance of the Regular Expression.

Example

The following example performs a regular expression search. It displays matches and submatches from the global RegExp object, and from the array that is returned by the exec method.

1

Properties

$1...$9 Properties | index Property | input Property | lastIndex Property | lastMatch Property | lastParen Property | leftContext Property | rightContext Property

Methods

The RegExp object has no methods.

Requirements

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

See Also

Regular Expression Object
Regular Expression Syntax (JavaScript)
String Object