Basic HTML version of Foils prepared 3 March 99

Foil 70 Anchoring and Alternation in Regular Expressions

From Overview of JavaScript I -- Basic Web Scripting Language CPS616 Technologies of the Information Age -- Spring Semester 99. by Geoffrey C. Fox (Tom Scavo)


1 For single characters, alternates can be specified by square brackets with
  • [abc] meaning a or b or c
2 For general strings one can use | to represent alternatives 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 (first year this course was taught!) 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
3 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 in earlier table)
  • \B matches NOT a word boundary so that
    • /Variable\B/ matches Variables but not Variable

in Table To:


© 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 Wed Mar 3 1999