You can group sub-expressions and offer them as alternatives. For example, you might want to match "AB" or "CD". The alternation operator can be placed between each sub-expression to indicate choices like this:
/AB|CD/
This technique can be used in combinations with character literals, classes and repetition operators. Like this:
/[a-z]{3}|[0-9]{40}/
This matches with three lower case letters or 40 numeric digits and nothing else will match.
ECMA 262 edition 3 - section - 15.10.1
ECMA 262 edition 3 - section - 15.10.2.3
ECMA 262 edition 3 - section - 15.10.2.4
Prev | Home | Next |
RegExp pattern | Up | RegExp pattern - attributes |
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. |