An Introduction to Regular Expressions The Basics 17 of 50 : [PREV] [NEXT]

Standard Meta Characters

Alternation (continued)

You can group various sorts with parentheses, as in the following expression:

/(Homer|Marge|Bart|Lisa|Maggie) Simpson/

A common mistake is to forget the parentheses:

/Homer|Marge|Bart|Lisa|Maggie Simpson/

Unlike the previous pattern, this one matches the followings strings, because "Simpson" belongs only to "Maggie":

  • "Simpson, Bart"
  • "Marge"
  • "Homer"

but it does not match the string "Maggie".


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