There are nine similarly named properties whose name is a dollar symbol followed by a single digit, each of these holding text matched by a sub-expression (in parentheses) for the most recent match.
The ECMAScript edition 3 specification suggests that the range of values for this is $01 to $99 and for an implementation to be ECMA compliant, it should support that range of possibilities. as well as the $1 to $9 values.
Since this is a class property (a static property), it belongs to the global built-in RegExp object. This means it is shared by all RegExp object instances and therefore is very transient and will be overwritten as soon as the next regular expression is evaluated. If you want to preserve the value, you will need to copy it immediately your regular expression has evaluated and before you call another.
Note that there are only 9 of these. If you create a complex pattern that has more than 9 sub-expressions, you won't be able to access the sub-expressions above the ninth one unless the implementation is fully compliant with ECMAScript edition 3.
Early versions of MSIE did not fully support this numbered property mechanism.
Prev | Home | Next |
RegExp.$_ | Up | RegExp.compile() |
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. |