perl – Regex to match any character including new lines

perl – Regex to match any character including new lines

If you dont 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:

[Ss]

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:.)

Add the s modifier to your regex to cause . to match newlines:

$string =~ /(START)(.+?)(END)/s;

perl – Regex to match any character including new lines

Yeap, you just need to make . match newline :

$string =~ /(START)(.+?)(END)/s;

Leave a Reply

Your email address will not be published.