Skip to content
DDevToolery

What each regex flag does

The seven flags, and when you actually need them.

Flags change how the whole pattern is applied. In the regex tools they are toggle buttons under the pattern box.

  • g — global. Find every match rather than stopping at the first. Almost always what you want when testing.
  • i — ignore case. Match without regard to upper or lower case.
  • m — multiline. ^ and $ match at every line break rather than only at the ends of the string.
  • s — dotAll. Lets . match newline characters, which it otherwise will not.
  • u — unicode. Treats the pattern as code points and enables \p{...} property escapes.
  • y — sticky. Matches only from the current position, with no scanning ahead.
  • d — indices. Records the start and end offset of every capture group.

The two that surprise people

m does not make . match newlines — that is s. And g changes the behaviour of repeated calls in JavaScript because the expression keeps a lastIndex between them, which is a common source of a regex that works once and then fails.

In the tools

The tester adds g automatically when finding matches, so the table shows all of them. Every flag button has a tooltip describing what it does.