Availability: |
| ||||||||
JavaScript syntax: | - | myRegExp = RegExp | |||||||
- | myRegExp = new RegExp() | ||||||||
- | myRegExp = RegExp(aPattern) | ||||||||
- | myRegExp = RegExp(aPattern, someAttribs) | ||||||||
Argument list: | aPattern | A regular expression pattern | |||||||
someAttribs | One 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.
The static properties of a regular expression object do not conform to the same static scoping rules as the rest of JavaScript. Their static or class based properties are dynamically scoped and available in the scope chain from which they are executed. This is not the same as the scope rules for functions which dictates that they run in the scope in which they are declared and not the scope from which they are called. This means that if a regular expression object is accessed in a function declared in one frame, when that function is called, the static properties are modified for the global built-in regular expression object that belongs to the calling frame. This avoids all manner of multithreaded simultaneous execution problems that would be difficult to deal with if the scoping rules for regular expression objects were the same as the rest of JavaScript.
In Netscape Navigator, many properties of the RegExp built-in object are enumerable but they are not available in this way in MSIE.
IE 5 does not properly support the RegExp object on the Macintosh platform. Many properties such as lastMatch, leftContext, etc. return an undefined value regardless of the RegExp result.
// 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;
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
$& | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
$' | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
$* | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
$+ | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
$_ | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | - |
$` | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
constructor | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
global | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ReadOnly. |
ignoreCase | 1.2 ![]() | 5.5 ![]() | 4.0 ![]() | 5.5 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ReadOnly. |
index | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | 5.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
lastIndex | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
prototype | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
source | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ReadOnly. |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
compile() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | - |
exec() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
test() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | 3.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
toSource() | 1.3 ![]() | ![]() | 4.06 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
toString() | 1.2 ![]() | 3.0 ![]() | 4.0 ![]() | 4.0 ![]() | 5.0 ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
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
Prev | Home | Next |
RegExp literal | Up | RegExp() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |