^ matches at the start of a string
$ matches at the end of a string
$x = /andrew/
$x =~ /^a/ ;
# matches as andrew starts with an a
$x =~ /rew$/;
# matches as andrew ends with a rew
But what if you have a string containing several lines (e.g. a file with \n characters) ?
The /m modifier.
This treats the string as multiple lines, so ^ and $ will match the start and end of each line in the file
This treats the string as a single line, so
$x = qq(
andrew
john andrew
andrew
);
$x =~ s/^andrew/ANDREW/mg;
# will replace 1st and 3rd andrew
# without the /m, it would only replace the third
No comments:
Post a Comment