Basic HTML version of Foils prepared March 30 97

Foil 45 Some regular expression Examples

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


1 /\s0(1+)/ matches "white space", followed by zero and 1 or more ones -- the set of ones is stored in \1 ($1)
2 /[0-9]\.0\D/ matches "the answer is 1.0 exactly" but not "The answer is 1.00".
  • 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
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 Sat Sep 6 1997