Basic HTML version of Foils prepared March 30 97

Foil 39 Grouping Patterns 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


1 Sequence is c1c2c3.. -- a sequence of single characters
2 * or {0,} is "zero or more" of previous character
3 + or {1,} is "one or more" of previous character
4 ? or {0,1} is "zero or one" of previous character
5 All matching is greedy -- they maximize number of characters "eaten up" starting with leftmost matching
  • In Perl5 one can follow specification with ? to instruct Perl5 to find smallest match (first occurrence) so that
  • .*?: matches to first : in line while .*: matches to last : in line.
6 Curly Brace Notation:
7 c{n1,n2} means from n1 to n2 instances of character c
8 c{n1,} means n1 or more instances of character c
9 c{n1} means exactly n1 instances of character c
10 c{0,n2} means n2 or less instances of character c

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