Basic HTML version of Foils prepared March 30 97

Foil 40 Anchoring and Alternation in Regular Expressions
(Chapter 7 of the Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


For single characters, alternates can be specified by square brackets with
  • [abc] meaning a or b or c
For general strings one can use | to represent or so that above example can also be written
  • a|b|c means a or b or c but this operator can be generalized to longer sequences so that 1995 CPS616 instructor can be written
  • Fox|Furmanski or if we can't spell Polish names
  • Fox|Furmansk(i|y|ie) # See later for use of parentheses
Patterns can be Anchored in four ways:
  • /^Keyname:/ matches to Keyname: ONLY if it starts string -- ^ only has this special meaning at start of regular expression
  • /Quit$/ matches Quit ONLY if it ends string -- $ only has this meaning if at end of regular expression
  • \b matches a word (PERL/C variable) boundary so that
    • /Variable\b/ matches Variable but not Variables ( inside [] construct, \b means a backspace as described earlier)
  • \B matches NOT a word boundary so that
    • /Variable\B/ matches Variables but not Variable



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Sep 6 1997