Regular Expressions Regex modifiers (flags) DOTALL modifier

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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) (e.g. (?s)cat (.*?) dog)

Note: In Ruby, the DOTALL modifier equivalent is m, Regexp::MULTILINE modifier (e.g. /a.*b/m).

Note: JavaScript does not provide a DOTALL modifier, so a . 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).



Got any Regular Expressions Question?