Basic HTML version of Foils prepared Sept 20 97

Foil 45 More Regex Examples

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


1 /\s0(1+)/ matches a "whitespace" character followed by a zero and one or more 1s -- the set of ones is stored in \1 (and $1)
2 /[0-9]\.0\D/ matches "the answer is 1.0 exactly" but not "the answer is 1.00" because of \D
  • In first case, $` is "the answer is ", $& is "1.0 " and $' is "exactly"
3 /a.*c.*d/ matches "axxxxcxxxxcdxxxxd" with
  • $` and $' as null and $& as full string (because greedy)
4 /(a.*b)c.*d/ matches "axxxxbcxxxxbd" with
  • \1 as "axxxxb" -- note backtracking as greedy (a.*b) first matches to "axxxxbcxxxxb" but then tries again when following c.*d fails to match

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 Sun Sep 21 1997