SCRIPT MERIDIAN
REGEX PROJECT
 

Regex Home

Download

Documentation
 Regex Verbs
 MatchInfo Table

 Metacharacters
  Grouping
  Anchors
  Character Classes
  Frontier Constants
  Quantifiers
  Alternation


Pointers

Credits

 

Alternation

A regular expression can contain a list of subexpressions, anyone of which might match the target. The list of subexpressions is delimited by "|"

Example
"First|1st|Winner" will match "First" or "1st" or "Winner".

Since regular expressions are greedy (ie they match the longest possible first match), the alternation metacharacter operates on the largest possible surrounding regular expression.

More technically, the alternational metacharacter has the lowest precedence of any regular expression operator.

Example
"this and|or that" will match "this and" or "or that".

To limit alternation, grouping brackets can be used.

Example
"this (and|or) that" will match "this and that" or "this or that" against the target string.



 [ Previous ]  [ Next  To the top  

Send questions and comments to regex@lists.scriptmeridian.org.
Page last updated: Thu, 10 Dec 1998 22:00:47 GMT.