$ can also match \ n
See Introduction to Perl Language, page 132, note 6
Can 1/^.*$/match "\ n"? Yes! Because the $ can match not only the end of the line, but also \ n
Can 2/^.*$/match "b\n"? Can be!. Can b match. \ n Match $
Can 3/^.*$/match "\NB"? No! Why? Because by default,. Cannot match \ n, change the pattern to/^.*$/s on it, and/s. can match any character, including \ n
Multiple-line match/M
Look at an example of this code output: Hello
Copy Code code as follows:
My $text = "Hello, World,\nhello zdd,\nhello Autumn";
while ($text =~/^hello/g) {
Print "hello\n"
}
A little change, plus the/m option
Copy Code code as follows:
My $text = "Hello, World,\nhello zdd,\nhello Autumn";
while ($text =~/^hello/mg) {
Print "hello\n"
}
Now the output becomes
Hello
Hello
Hello
Annotations:
By default, ^ and $ match the beginning and end of the entire string, but after plus/m, the ^ and $ match the beginning and end of each line. That is, because there is a newline character in the string \ n, the/m option causes ^$ to match the beginning and end of each line.
If there are no newline characters in the string, the/m option does not work.