Positional anchors can be constructed using patterns. These are enclosed in grouping operators and commence with a question mark.
A logical negation is also possible. However the syntax for this uses the JavaScript convention of an exclamation mark (!) rather than the regular expression convention of a circumflex (^).
A positional anchor, marking the location immediately before a capital letter would look like this:
(?=[A-Z])
A positional anchor marking a location immediately before any non-capital letter would look like this:
(?![A-Z])
The second example uses the logical negation operator.
Note that these are positional anchors that behave like the ^ and $ which denote the start and end of a line. They do not select any characters.
ECMA 262 edition 3 - section - 15.10.1
ECMA 262 edition 3 - section - 15.10.2.7
ECMA 262 edition 3 - section - 15.10.2.14
Prev | Home | Next |
RegExp pattern - character literal | Up | RegExp pattern - grouping |
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. |