The Comprehensive Guide to Regex Flags (g, i, m, s, u)
Modifiers (or flags) sit outside the regex and alter the global behavior of the engine. Knowing when to toggle these is crucial.
The Big Four
i (Case Insensitive)
Treats 'A' and 'a' as identical. Essential for user input.
g (Global)
Example: replaceAll. Without this, the engine stops after the first valid match.
m (Multiline)
Changes the behavior of anchors ^ and $ to match the start/end of lines rather than the whole string.
s (DotAll)
Makes the dot . match newlines (\n). By default, dots stop at newlines.