An intrinsic global object that stores information about the results of regular expression pattern matches.
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 illustrates the use of the global RegExp object.
Copy Code | |
---|---|
function matchDemo(){ var s; var re = new RegExp("d(b+)(d)","ig"); var str = "cdbBdbsbdbdz"; var arr = re.exec(str); s = "$1 contains: " + RegExp.$1 + "\n"; s += "$2 contains: " + RegExp.$2 + "\n"; s += "$3 contains: " + RegExp.$3; return(s); } |
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.