$w = "The wings of desire bore Adrian ever higher over the darkling
abyss of life as a scullery lad.";
if ($w =~ /abyss/) {
print "Too romantic! \n";
}
($w =~ /bore/) && print "Put some life into it! \n";
/a+/ matches 1 or more a's
/a*/ matches 0 or more a's
/a?/ matches 0 or 1 a's
"This is a test" =~ /T..s/; # matches 'This' "This is a test" =~ /T.*s/; # matches 'This is a tes' "This is a test" =~ /s[^\s]/ # matches 'st'
This is particularly useful when used in conjunction with parentheses. If you include a pair of parentheses in a regular expression, the sub-expression that matches the regular expression they enclosed is stored in a variable called $1. If you have two pairs, the matches are stored in $1 and $2, etc.$x = s/reg expr/thing to substitute/
$w = "This is a mistake dyslexic"; $w =~ s/(mistake) (dyslexic)/$2 $1 \n/; print $w;
The Geometry Center Home Page
Comments to:
webmaster@geom.umn.edu
Created: May 07 1996 ---
Last modified: May 29 1996