Regex Flags Explained
understand what regex flags g, i, m, s, u, y do with live examples
By Bikram NathLast updated
Regex flags change how a pattern matches without altering the pattern itself. The global flag (`g`) makes `/cat/g` find every occurrence in a string instead of stopping after the first; without it, `'catcat'.match(/cat/)` returns only one result. The `s` (dotAll) flag is the one most developers forget exists — it makes `.` match newline characters, which it silently skips by default.
Try it now — free, instant, no signup
What is Regex Flags Explained?
Regex Flags Explained is an interactive reference that runs each ECMAScript flag in isolation and in combination, showing you live how the same pattern behaves differently with and without each modifier. Paste a pattern and a test string, toggle flags one at a time, and the match output updates immediately so you can see, for example, that adding `i` to `/hello/` makes it match 'Hello', 'HELLO', and 'hElLo' without touching the pattern.
Developers typically reach for regex101 when they need a full-featured debugger with a match-step visualizer and regex flavor switching (PCRE, Python, Java). This tool is narrower: it focuses exclusively on JavaScript's six flags and is useful when you already know your pattern works but you're unsure which combination of flags to ship with it, or when you want to teach a colleague what `m` actually does to `^` and `$`.
The most common confusion with flags involves `m` versus `s`. The multiline flag (`m`) does not make `.` span lines — it only changes where `^` and `$` anchor. To make `.` cross a newline you need `s`, which was added in ECMAScript 2018 and is unavailable in Node.js below v10. The `y` (sticky) flag is subtler still: it respects `lastIndex` and will fail a match rather than scanning forward, which makes it useful for tokenizers but confusing in one-off scripts.