A regex pattern where a DOTALL modifier (in most regex flavors expressed with
s) changes the behavior of
. enabling it to match a newline (LF) symbol:
/cat (.*?) dog/s
This Perl-style regex will match a string like
"cat fled from\na dog" capturing
"fled from\na" into Group 1.
An inline version:
(?s)cat (.*?) dog)
Note: In Ruby, the DOTALL modifier equivalent is
Regexp::MULTILINE modifier (e.g.
. can never be allowed to match a newline character. In order to achieve the same effect, a workaround is necessary, e. g. substituting all the
.s with a catch-all character class like
[\S\s], or a not nothing character class
[^] (however, this construct will be treated as an error by all other engines, and is thus not portable).