Basic HTML version of Foils prepared Sept 20 97

Foil 40 Repetition in Regular Expressions

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


1 Sequence is c1c2c3.. -- a sequence of single characters
2 c* means "zero or more" instances of character c
3 c+ means "one or more" instances of character c
4 c? means "zero or one" instances of character c
5 All matching is greedy -- the maximum number of chars are "eaten up" starting with leftmost matching character
  • In Perl5, use ? to override greedy matching of regex parser
  • .*?: 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 Sun Sep 21 1997