g · i · m · s · u · y · d · live examples

Every JS regex flag with a before / after example

Seven flags explained with a worked example each — pattern, sample text, and side-by-side match counts with and without the flag.

Regex Flag Reference
Flags
7
ECMA
Examples
7
live
Total matches
15
with flag
Off matches
10
no flag
flag · letter + name
gglobal
Find all matches, not just the first.
iignoreCase
Case-insensitive matching.
mmultiline
^ and $ match at each line boundary.
sdotAll
Dot . matches newlines too.
uunicode
Treat pattern as Unicode; enable \p{...} properties.
ysticky
Match only from lastIndex (no scanning ahead).
dindices
Result includes per-group start/end indices.
example · pattern + sample + counts
/\d+/
1 fish 2 fish 3 fish
off: 3 matches · "1"
with g: 3 matches · "1"
/hello/
Hello there, HELLO again, hello world
off: 1 match · "hello"
with i: 3 matches · "Hello"
/^line/
line one line two line three
off: 1 match · "line"
with m: 3 matches · "line"
/a.b/
a b
off: 0 matches
with s: 1 match · "a\nb"
/\p{L}+/
café niño ☃
off: 0 matches
with u: 2 matches · "café"
/ab/
ababab
off: 3 matches · "ab"
with y: 1 match · "ab"
/(foo)(bar)/
foobar foobar
off: 2 matches · "foobar"
with d: 2 matches · "foobar"
Quick Start

How to read the flag reference

One card per flag — pattern, sample, and side-by-side counts make the effect obvious.

  1. 01

    Pick a flag

    Browse the list — g, i, m, s, u, y, d.

    Each entry corresponds to a single character in the ECMAScript regex literal suffix — g (global), i (case-insensitive), m (multiline), s (dotAll), u (Unicode), y (sticky), and d (hasIndices).

    navECMAScriptliteralreference
    flags · indexed7 · ECMA
    g i m s u y d
    loaded · indexedECMA · ready
  2. 02

    Read the example

    Each card shows pattern, sample, and counts off vs on.

    Examples run live through the JavaScript RegExp engine — the counts you see are the same numbers String.matchAll would return at runtime.

    exampleliveRegExpmatchAll
    config · example/\d+/ · live
    1 fish 2 fish 3 fish
    flags applied · liveECMA · live
  3. 03

    Compare counts

    Off vs with-flag tells you immediately what the flag changes.

    The side-by-side count is the cleanest way to disambiguate g (find-all) from non-g (find-first) and to see when i or m actually moves the needle on your data.

    comparedeltamatch countlive
    run · matches1 · 3
    off: 1  with g: 3
    matches · livegroups · live
  4. 04

    Try it live

    Click through to the Regex Tester to play with your own input.

    The Tester carries forward your pattern and flags so you can switch instantly from reading the reference to authoring a real regex against production sample text.

    exploretesterlivedeep-link
    export · testerready · deep-link
    Open tester →
    ready to shipsuccess
Pro tips

Regex patterns that don't melt down

Use named groups

(?<year>\d{4}) reads better than $1 and survives reordering. Supported in ECMAScript 2018+.

Anchor strictly

Use ^/$ with the m flag when matching whole lines. Without anchors, partial matches sneak through.

Avoid catastrophic backtracking

Nested quantifiers like (a+)+ can explode. Run patterns through ReDoS Detector first.

Escape every literal

Backslash any meta character you want literally: \.\$\^\*\+\?\(\)\[\]\{\}\|\\.

Test edge cases

Empty string, single character, unicode, the maximum length you expect — write fixtures for each.

Patterns aren&rsquo;t parsers

Don’t parse HTML, JSON, or balanced parens with regex. Use a proper parser when the grammar is recursive.

Use Cases

When to consult the reference

Developers, learners, code reviewers.

Memorise flag effects

See exactly what g, m, s and u do without testing. Compiles through the JavaScript RegExp constructor — engine quirks (Unicode property escapes, sticky matching, named groups) work when their flags are on. Error messages cite the exact position of any syntax issue.

ReDoS-safe

PR review

Confirm a flag change actually changes behaviour. Pairs with the ReDoS detector to catch catastrophic backtracking before you deploy. A pattern that handles 1k-character input fine can become a denial-of-service vector on attacker-controlled 1M-character input.

ECMA-compliant

Author regex

Pick the right flag combination quickly. Output exports as JavaScript, Python re, Java util.regex, .NET System.Text.RegularExpressions, PCRE, and POSIX — language quirks are highlighted on conversion so you don't ship a JS-only pattern to a Go service.

spec-grade

Debug

Suspecting i is missing? Compare counts here. Capture groups (named or numbered) round-trip cleanly into replacement strings, JSON output, or CSV extraction without re-typing. Backreferences ($1, ${name}) preserve semantics across languages.

cross-engine

Teach

Show students the difference in a single screen. Test against edge cases — empty input, single character, max length, multibyte boundaries — to catch off-by-one and zero-length match bugs before they reach production.

test-ready

Cross-flavour

Spot which flags are JS-only. All matching runs client-side so secret patterns never leave the browser. Useful when the pattern itself is sensitive (PII regexes, internal data formats, security filters).

production-ready
FAQ

Frequently asked questions

All seven shown — g, i, m, s, u, y, d. ES2022 added d for indices, ES2018 added s.
ES2024 added /v for Unicode set notation. We'll add it once browser support is widespread.
Yes — /gim is common. Try the Flag Tester to compare combinations side by side.
Sticky matching from lastIndex. Less common in app code but useful in parsers.
No. Examples run entirely in your browser.
Suggest a tool

Something missing?

Tell us what you need. We ship the top requests every two weeks.

Sent straight to the maintainers · no account needed
47 in queue·8 shipped this month
Request queued. Thanks!