An Introduction to Regular Expressions Matching Rules 42 of 50 : [PREV] [NEXT]

Rule 2

For this rule, the whole regular expression is regarded as a set of alternatives, separated by vertical bars (|). A regular expression can obviously consist of only one alternative, in which case it does not have any vertical bar. There's no such thing as zero alternatives because a null string can always match something of zero width.

A set of alternatives matches a string if any of the alternatives match under Rule 3. It tries the alternatives from left-to-right, and stops on the first match that allows successful completion of the entire regular expression. If none of the alternatives match, the Engine backtracks to the Rule that invoked this Rule, which is usually Rule 1, but could be Rule 4 or 6. That Rule then looks for a new position at which to apply Rule 2.


© 2003 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/