Basic HTML version of Foils prepared March 30 97

Foil 43 The Matching Operator in Regular Expressions - II
Variable Interpolation; i,g options; general substitution
(Chapter 7 of the Llama Book)

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


Variables may be used in Regular expressions and are interpolated as in usual double quoted strings. Use \$ to represent a real dollar except at end of string when it safely represents end of string anchor.
In match /regexp/i , the i instructs one to ignore case in match
In substitution s/regexp1/regexp2/g, the g instructs substitution to occur at all possible places in string -- normally only the first match in a string is found
i and g can be used together
$line =~ s/regexp1/regexp2/ ; # Illustrates how we use substitution s on general variable
As with m, s can use any delimiter and so
$line =~ s#regexp1#regexp2# ; # is equivalent form



© 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