RegExp object (Object/core)

An object that encapsulates regular expressions.

Availability:

ECMAScript edition - 3
JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Netscape Enterprise Server - 3.0
Opera 5.0
JavaScript syntax:-myRegExp = RegExp
-myRegExp = new RegExp()
-myRegExp = RegExp(aPattern)
-myRegExp = RegExp(aPattern, someAttribs)
Argument list:aPatternA regular expression pattern
someAttribsOne or more regular expression attributes
Class properties:$n, index, input, lastMatch, lastParen, leftContext, multiline, rightContext
Object properties:$&, $', $*, $+, $_, $`, constructor, global, ignoreCase, index, lastIndex, prototype, source
Object methods:compile(), exec(), test(), toSource(), toString()

The RegExp object implements some class (or static) methods which is fairly untypical of classes that support a constructor. There are also instance methods and properties.

Warnings:

Example code:

   // Create a RegExp object using a constructor

   var myRegExp = new RegExp("sque[ea]ky", "g");

   // Create the same RegExp object with a reg exp literal

   var myRegExp = /sque[ea]ky/g;

See also:Function scope, RegExp pattern - character literal, RegExp(), RegExp.multiline, unwatch(), watch()

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
$&1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aWarning
$'1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aWarning
$*1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aWarning
$+1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aWarning
$_1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.0 n/a n/a n/a n/a-
$`1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aWarning
constructor1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.0 n/a3 3 n/a n/a n/a-
global1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aReadOnly.
ignoreCase1.2 1.25.5 5.54.0 4.05.5 5.55.0 5.03.0 3.03 3 n/a n/a n/aReadOnly.
index n/a3.0 3.0 n/a4.0 4.05.0 5.0 n/a n/a n/a n/a n/a-
lastIndex1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aWarning
prototype1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.0 n/a3 3 n/a n/a n/a-
source1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aReadOnly.

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
compile()1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.0 n/a n/a n/a n/a-
exec()1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/aWarning
test()1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.03.0 3.03 3 n/a n/a n/a-
toSource()1.3 1.3 n/a4.06 4.06 n/a n/a n/a n/a n/a n/a n/a-
toString()1.2 1.23.0 3.04.0 4.04.0 4.05.0 5.0 n/a3 3 n/a n/a n/a-

Cross-references:

ECMA 262 edition 3 - section - 15.1.4.8

ECMA 262 edition 3 - section - 15.10.3

ECMA 262 edition 3 - section - 15.10.4