Coding Tool

Regex Tester & Debugger

Test regular expressions with live match highlighting, capture groups, replace mode, and a full cheatsheet — all in your browser.

/ /
Status
Matches
Pattern
Test length
Test String
Match Results
Showing first 50 of matches.
Replace Output

  

Ready-to-Use Regex Snippets

Click any snippet to load it directly into the tester. All patterns are production-tested.

Regex Cheatsheet

Every token you need — from basic anchors to advanced lookarounds.

Anchors
^Start of string (or line with m)
$End of string (or line with m)
\bWord boundary
\BNon-word boundary
\AStart of string (no multiline)
\ZEnd of string (no multiline)
Character Classes
.Any char except newline (use s flag)
\dDigit [0-9]
\DNon-digit
\wWord char [a-zA-Z0-9_]
\WNon-word char
\sWhitespace (space, tab, newline…)
\SNon-whitespace
Quantifiers
*0 or more (greedy)
+1 or more (greedy)
?0 or 1 (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*? +? ??Lazy (minimal match)
Groups & Alternation
(abc)Capture group
(?:abc)Non-capturing group
(?<name>)Named capture group
a|ba or b (alternation)
\1 \2Back-reference to group 1, 2
\k<name>Back-reference by name
Lookarounds
(?=abc)Lookahead — followed by abc
(?!abc)Negative lookahead
(?<=abc)Lookbehind — preceded by abc
(?<!abc)Negative lookbehind
Character Sets
[abc]Match a, b, or c
[^abc]Not a, b, or c
[a-z]Lowercase letters
[A-Z]Uppercase letters
[0-9]Digits
[a-zA-Z]Any letter
Flags
gGlobal — find all matches
iCase insensitive
mMultiline — ^ $ per line
sDotall — . matches \n
uUnicode mode
ySticky — match from lastIndex
Replace References
$&Whole match
$1 $2 …Capture group by number
$<name>Named capture group
$`Text before match
$'Text after match
$$Literal $ sign

How to Use This Tool

Everything the regex tester does and how to get the most out of each feature.

1
Write Your Pattern
Type your regex pattern in the input bar. Toggle the g i m s flag buttons to set global, case-insensitive, multiline, and dotall modes. Errors show immediately below.
2
Paste Test Text
Enter or paste your test string. Matches highlight in real time — purple for full matches. The match count updates instantly in the stats bar.
3
Inspect Capture Groups
Each match result shows its capture groups as colour-coded pills. Groups are numbered $1, $2, etc. — the same references you use in replace operations.
4
Test Replace
Toggle Replace mode and type your replacement string. Use $1, $2, $& to reference groups and the full match. The replaced output appears below.
5
Load a Snippet
Pick from 16 production-ready patterns — email, URL, phone, date, hex colour, credit card, password and more. Clicking a snippet loads it directly into the tester.
6
Use the Cheatsheet
The cheatsheet below the snippets covers anchors, character classes, quantifiers, groups, lookarounds, flags, and replace references — everything you need without leaving the page.

What's Built In

A full regex workbench — no extensions, no sign-up, nothing sent to a server.

🔦
Live Highlighting
Every match highlighted in the test string as you type — no button press needed.
🎯
Capture Groups
Group values shown as colour-coded pills under each match, numbered to match your replace references.
🔁
Replace Mode
Full replace with $1 $2 $& references. See the substituted result instantly.
🚩
All Four Flags
Toggle g, i, m, s individually — global, case-insensitive, multiline, dotall.
📚
16 Snippets
Email, URL, phone, date, hex colour, password, credit card, markdown links, and more.
📋
Cheatsheet
Eight categories covering every token — anchors, quantifiers, lookarounds, replace references.
🔒
100% Private
Runs entirely in your browser using the native JS RegExp engine. Nothing leaves your device.
📊
Match Stats
Match count, match positions (index range), and total test string length shown in the stats bar.

Frequently Asked Questions

Common questions about regex and how this tester works.

This tool uses the JavaScript RegExp engine built directly into your browser. It supports all standard JavaScript regex features including lookahead, lookbehind (in modern engines), named capture groups ((?<name>...)), and the g, i, m, s, u, and y flags. The engine is the same one used by String.prototype.match() and String.prototype.replace() in your JavaScript code.

The g flag is on by default in this tool because most people testing regex want to see all matches in a body of text, not just the first one. Without g, regex.exec() and string.match() stop at the first match. Toggling it off is useful when you specifically want to test that a pattern matches exactly once or to measure first-match behaviour.

Wrap part of your pattern in parentheses to create a capture group. For example, (\d{4})-(\d{2})-(\d{2}) creates three groups for year, month, and day. Each match in the results panel shows the captured values as colour-coded pills labelled $1, $2, $3. In replace mode, reference groups with those same labels: replacing (\d{4})-(\d{2})-(\d{2}) with $3/$2/$1 converts ISO dates to DD/MM/YYYY.

Greedy quantifiers (*, +, {n,m}) consume as many characters as possible while still allowing the overall pattern to match. Lazy quantifiers (*?, +?, {n,m}?) consume as few as possible. For example, against <b>bold</b>, the pattern <.*> (greedy) matches the entire string in one match, while <.*?> (lazy) matches <b> and </b> separately. Use lazy matching when parsing HTML-like or nested content.

A lookahead asserts that what follows the current position matches (or doesn't match) a pattern, without consuming characters. (?=abc) is a positive lookahead — "match if followed by abc". (?!abc) is negative — "match if NOT followed by abc". Lookbehinds ((?<=...)) work the same way but look backwards. Use lookarounds when you need to validate context around a match without including that context in the captured result — for example, \d+(?= dollars) matches a number only if the word "dollars" follows it.

Over-matching is usually caused by: (1) greedy quantifiers — try adding ? after * or + to make them lazy; (2) missing anchors — add ^ and $ to enforce a full-string match; (3) . matching more than intended — use a character class like [^,\n] instead to stop at delimiters; (4) missing boundaries — add \b around word patterns to prevent partial word matches.

Escape the character with a backslash: \. matches a literal dot, \[ and \] match brackets, \( and \) match parentheses, \* matches an asterisk. In a JavaScript string, you need a double backslash because the string parser consumes one: new RegExp('\\.'). In a regex literal /\./ you only need one backslash.

Catastrophic backtracking (ReDoS) happens when a regex with nested quantifiers — like (a+)+ — takes exponential time on certain inputs because the engine retries enormous numbers of possible match paths. It can freeze a browser tab or crash a Node.js server. Prevention: avoid nested quantifiers, use possessive quantifiers or atomic groups if the engine supports them, prefer specific character classes over broad ones, and test patterns against adversarial inputs before deploying to production.

Enable the m (multiline) flag — this makes ^ and $ match the start and end of each line, not just the entire string. To match content that spans lines (e.g. a block comment), you also need the s (dotall) flag so . matches newline characters. For example, /\/\*.*?\*\//gs matches /* ... */ comments even when they span multiple lines.

This tool uses the JavaScript regex engine, which is largely compatible with Python re and PHP preg for common patterns. Key differences: Python supports \A and \Z as string anchors; PHP defaults to PCRE which supports possessive quantifiers and atomic groups; Python doesn't have the s flag — use re.DOTALL instead. For complex patterns targeting non-JavaScript environments, verify the final result in the actual runtime.

Related Tools

View all →

Related Articles

View all →