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.
Flag Reference
g /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 /i Case-insensitive matching. /hello/i matches Hello, HELLO, hElLo.
/hello/i on "Hello World" → 1 match m /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 /s Makes . match any character including newlines (\n). Normally . does not match newlines.
/.+/gs on "line1\nline2" → full string match u /u Enables full Unicode support. Treats surrogate pairs correctly. Required for emoji and non-BMP characters.
/\u{1F600}/u matches 😀 correctly y /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.
Related Products
on GumroadTypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →DevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →You Might Also Need
Regex Tester Pro
Free Regex Tester Pro with real-time match highlighting. Test regular expressions with live visual feedback. Supports JS, Python, and Ruby flavors, all flags, capture groups, and 6 built-in presets. R
Open free tool →
Regex Tester
Free regex tester. Test regular expressions against multiple strings with expected match/no-match assertions — see instant pass/fail results. Built-in presets for email, URL, IPv4, and phone. Pro: unl
Open free tool →
AI Regex Explainer — Pro Tool
Paste any regular expression and get a plain-English breakdown, match examples, and gotchas. Explains capture groups, lookaheads, and common mistakes. Free regex explainer tool. DevPlaybook Pro featur
Open free tool →
More Free Tools
Related Articles
How to Test Regular Expressions: Complete Beginner Guide
Learn how to test regular expressions step by step. This beginner guide covers regex syntax, how to use online testers, common patterns, and debugging techniques with practical examples.
Best Free Regex Testers for Web Developers
The best free online regex testers for web developers in 2025. Compare features, language support, and find the right regex testing tool for your workflow.
Bun Shell Scripting Guide: Replace Bash Scripts with $.cmd() and Bun APIs
Learn how to replace complex bash scripts with Bun's built-in shell API. Covers $.cmd(), Bun.file(), spawn(), and practical real-world automation scripts.
TypeScript 5.5 New Features: Complete Guide for Developers 2026
Everything you need to know about TypeScript 5.5: inferred type predicates, isolated declarations, JSDoc @import tag, new Set methods, and performance improvements. With practical code examples.
Monorepo Tools Compared: Turborepo vs Nx vs Moon 2026
A comprehensive comparison of the top monorepo tools in 2026 — Turborepo, Nx, and Moon. Learn setup, remote caching, task orchestration, CI integration, and how to choose the right tool for your team.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →