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


1 The substitution operator s has the form:
2 $line =~ s/regex1/regex2/ ;
3 As with m, the operator s can use any delimiter and so
4 $line =~ s#regex1#regex2# ;
5 is an equivalent form
6 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)
7 Note that /i and /g can be used together
8 In an HTML doc, replace 2x2 with <NOBR>2 x 2 </NOBR>
9 Search: (\d+)x(\d+)
10 Replace: <NOBR>\1 x \2</NOBR>
11 PERL: s|(\d+)x(\d+)|<NOBR>\1 x \2</NOBR>|i

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