The dot loses its special meaning inside a character class — in other words, [.\s]
means "match period or whitespace". I believe what you want is [\s\S]
, "match whitespace or non-whitespace".
preg_replace('/#BIZ[\s\S]*#ENDBIZ/', 'my new text', $strMultiplelines);
Edit: A bit about the dot and character classes:
By default, the dot does not match newlines. Most (all?) regex implementations have a way to specify that it match newlines as well, but it differs by implementation. The only way to match (really) any character in a compatible way is to pair a shorthand class with its negation — [\s\S]
, [\w\W]
, or [\d\D]
. In my personal experience, the first seems to be most common, probably because this is used when you need to match newlines, and including \s
makes it clear that you're doing so.
Also, the dot isn't the only special character which loses its meaning in character classes. In fact, the only characters which are special in character classes are ^
, -
, \
, and ]
. Check out the "Metacharacters Inside Character Classes" section of the character classes page on Regular-Expressions.info.