Skip to main content

Regex Flags Explainer

Enter a regex pattern and test string, then toggle flags to see how each one changes what matches. Covers all 6 JavaScript regex flags: g, i, m, s, u, and y.

✓ Live match highlighting ✓ Per-flag explanation ✓ Toggle flags interactively ✓ Runs 100% in your browser
/ / g
Match Results

Flag Reference

g
global /g

Find all matches instead of stopping after the first. Required for replace-all and match-all operations.

/hello/g on "hello hello" → 2 matches
i
ignoreCase /i

Case-insensitive matching. /hello/i matches Hello, HELLO, hElLo.

/hello/i on "Hello World" → 1 match
m
multiline /m

Makes ^ match start-of-line and $ match end-of-line (not just start/end of string).

/^hello/gm on "hello\nworld\nhello" → 2 matches
s
dotAll /s

Makes . match any character including newlines (\n). Normally . does not match newlines.

/.+/gs on "line1\nline2" → full string match
u
unicode /u

Enables full Unicode support. Treats surrogate pairs correctly. Required for emoji and non-BMP characters.

/\u{1F600}/u matches 😀 correctly
y
sticky /y

Only matches at the exact position of regex.lastIndex. Does not advance through the string like g.

/hello/y with lastIndex=6 only matches at position 6

Frequently Asked Questions

What does the g (global) flag do in regex?▼

The g (global) flag makes the regex find all matches instead of stopping after the first one. Without g, methods like String.match() return only the first match. With g, they return an array of all matches. String.replace() with g replaces all occurrences; without it, only the first is replaced.

What does the i (case insensitive) flag do?▼

The i flag makes the regex match regardless of letter case. /hello/i matches 'Hello', 'HELLO', 'hElLo', and 'hello'. This is useful for user input validation where you don't want case to matter, like checking for keywords or usernames.

What is the m (multiline) flag used for?▼

The m flag changes how ^ and $ anchors behave. Without m, ^ matches the start of the entire string and $ matches the end. With m, ^ matches the start of each line and $ matches the end of each line. This is essential when processing multi-line text where you want to match patterns at line boundaries.

What does the s (dotAll) flag do?▼

The s flag (also called dotAll) makes the dot (.) match any character including newlines. Normally, . matches everything except \n (newline). With /s, . matches \n too, which is useful for matching patterns that span multiple lines like HTML tags or multi-line strings.

When should I use the u (unicode) flag?▼

The u flag enables proper Unicode support. Without it, regex treats emoji and characters outside the Basic Multilingual Plane (BMP) as two surrogate pairs. With /u, \w, \b, and character classes work correctly with Unicode. Use /u whenever your input may contain non-ASCII characters or emoji.

What is the y (sticky) flag?▼

The y flag makes the regex 'sticky' — it only matches at the exact position stored in regex.lastIndex. Unlike g which searches the whole string, y only succeeds if a match starts right at lastIndex. This is used in tokenizers and parsers where you need sequential matching at exact positions.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →