For example, this regex
(.*)<FooBar>
will match:
abcde<FooBar>
But how do I get it to match across multiple lines?
abcde
fghij<FooBar>
For example, this regex
(.*)<FooBar>
will match:
abcde<FooBar>
But how do I get it to match across multiple lines?
abcde
fghij<FooBar>
In JavaScript, use
/[\S\s]*<Foobar>/
. SourceTry this:
It basically says "any character or a newline" repeated zero or more times.
generally . doesn't match newlines, so try
((.|\n)*)<foobar>
the s causes Dot (.) to match carriage returns
Note that
(.|\n)*
can be less efficient than (for example)[\s\S]*
(if your language's regexes support such escapes) and than finding how to specify the modifier that makes . also match newlines. Or you can go with POSIXy alternatives like[[:space:][:^space:]]*
.Solution:
Use pattern modifier sU will get the desired matching in PHP.
example:
Source:
http://dreamluverz.com/developers-tools/regex-match-all-including-new-line http://php.net/manual/en/reference.pcre.pattern.modifiers.php