
22
|
JavaScript Pocket Reference
Anchoring match position
An anchor in a regular expression matches a position in a
string (such as the beginning or the end of the string) with-
out matching any of the characters of a string. It can be used
to restrict (or anchor) a match to a specific position within a
string.
Versions of JavaScript
Netscape has defined a number of versions of JavaScript.
Microsoft has released more-or-less compatible versions
under the name “JScript,” and the ECMA standards body
has released three versions of a JavaScript standard named
“ECMAScript”. The following paragraphs describe these var-
ious versions, and explain how they relate to each other.
Each entry in the reference section contains availability infor-
Character Meaning
a | b Match either a or b
(sub)
Group subexpression sub into a single term, and remember the text
that it matched
(?:sub) Group subexpression sub but do not number the group or
remember the text it matches (JS 1.5)
\n Match exactly the same characters that were matched by group
number
n
$n
In replacement strings, substitute the text that matched the nth
subexpression
Character Meaning
^, $ Require match at beginning/end of a string, or in multiline mode,
beginning/end of a line
\b, \B Require match at a word boundary/non-boundary
(?=p) Look-ahead assertion: require that the following characters match
the pattern p, but do not include them in the match. (JS 1.5)
(?! ...