Mega Code Archive

 
Categories / Perl / Regular Expression
 

Pattern match

$str="old and restless"; print "$&\n" if $str =~ /and/; print "$'\n" if $str =~ /and/; print "$'\n" if $str =~ /and/; print "\nold string is: $str\n"; $str=~s/(old) and (restless)/$2 and $1/; print "new string is: $str\n"; print "\nlast pattern matched: $+\n";