Is there a regex to match \"all characters including newlines\"?
For example, in the regex below, there is no output from $2
because (.+?)
If you don't want add the /s
regex modifier (perhaps you still want .
to retain its original meaning elsewhere in the regex), you may also use a character class. One possibility:
[\S\s]
a character which is not a space or is a space. In other words, any character.
You can also change modifiers locally in a small part of the regex, like so:
(?s:.)
Yeap, you just need to make .
match newline :
$string =~ /(START)(.+?)(END)/s;
You want to use "multiline".
$string =~ /(START)(.+?)(END)/m;
Add the s modifier to your regex to cause .
to match newlines:
$string =~ /(START)(.+?)(END)/s;