Basic HTML version of Foils prepared Sept 20 97

Foil 47 The Substitution Operator and
Regular Expressions

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


The substitution operator s has the form:
$line =~ s/regex1/regex2/ ;
As with m, the operator s can use any delimiter and so
$line =~ s#regex1#regex2# ;
is an equivalent form
In the substitution s/regex1/regex2/g the /g causes substitution to occur at all possible places in string (normally only the first match is found)
Note that /i and /g can be used together
In an HTML doc, replace 2x2 with <NOBR>2 x 2 </NOBR>
Search: (\d+)x(\d+)
Replace: <NOBR>\1 x \2</NOBR>
PERL: s|(\d+)x(\d+)|<NOBR>\1 x \2</NOBR>|i



© 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