Regex Tester
//
2 matches
Auto-saved
Test StringType or paste text to test against
Capture Groups0 groups · 2 matches
No capture groups. Use (…) to capture.
Quick Reference
.Any char except newline
\dDigit [0-9]
\wWord char [a-zA-Z0-9_]
\sWhitespace
\bWord boundary
^Start of string/line
$End of string/line
*0 or more
+1 or more
?0 or 1 (optional)
{n,m}Between n and m times
(abc)Capture group
(?:abc)Non-capture group
(?<n>…)Named group
[abc]Character class
[^abc]Negated class
a|bAlternation (a or b)
(?=…)Lookahead
(?!…)Neg. lookahead
(?<=…)Lookbehind

Regex Tester Online Free — Live Match Highlighting, Capture Groups & Replace Preview

Updated May 14, 2026
Share & Support

What's included

Features

Live inline match highlighting — every match shown as a colored span in the test string as you type
Capture group table — shows every match as a row with each numbered or named group value in its own column
Named capture groups — (?<name>…) syntax with group name shown as column headers in the capture table
Replace mode — enter a replacement string with $1, $2, $<name> group references and preview the result live
All 5 JS flags — g (global), i (case-insensitive), m (multiline), s (dot-all), u (unicode) as toggle buttons
10 ready-to-use presets — Email, URL, IPv4, Hex Color, ISO Date, US Phone, HTML Tag, JWT, Markdown Bold, CSS Class
Inline error display — shows the exact browser error message for invalid patterns
Match count in header — total match count and capture group count shown at a glance
Quick reference panel — 20 essential regex tokens with syntax examples
Copy button — copies pattern in /pattern/flags format with one click
100% client-side — uses the native browser RegExp engine, nothing uploaded; view structured JSON matches in our JSON Table Viewer

About this tool

Test JavaScript Regex Online — See Matches Instantly as You Type

Runs in your browser
No install or signup
Free forever

You wrote a regex pattern and you're not sure it's matching what you think. Maybe it matches too much, or nothing at all. Maybe the capture groups aren't capturing the right parts, or the replace is producing the wrong output. You could open the browser console and type new RegExp("pattern").exec("string") and console.log the result — or you can paste both here and see every match highlighted inline in a second.

Type a pattern, toggle the flags you need, paste your test string, and matches are highlighted in real time — no button click, no reload, no delay. Every change to the pattern, flags, or test string instantly re-runs the regex engine and updates the highlights, match count, and capture group table.

Capture groups are the hardest part to debug. Wrap any part of your pattern in parentheses and the capture groups table shows every match as a row, with each group's value in its own labelled column. Named capture groups using (?<name>…) syntax show the group name as the column header — so instead of Group 1, Group 2, you see "year", "month", "day". That makes complex multi-group patterns readable at a glance, without console.log.

Replace mode lets you preview a string.replace() operation before writing the code. Enter a replacement string using $1, $2, or $<name> references and the transformed output appears immediately. Verify the replace logic works before deploying it.

If you're not sure where to start, the 10 built-in presets load a pattern, flags, and sample test string in one click: Email, URL, IPv4, Hex Color, ISO 8601 Date, US Phone, HTML Tag, JWT, Markdown Bold, and CSS Class. The quick reference panel lists 20 essential regex tokens — anchors, quantifiers, groups, lookaheads, and character classes — so you don't have to remember the syntax by heart.

Everything runs in your browser using the native JavaScript RegExp engine. No install, no sign-up, no server requests.

Step by step

How to Use

  1. 1
    Type your regex pattern in the pattern barEnter your regular expression in the /pattern/ input bar at the top. You do not need to include the surrounding forward slashes — just the pattern itself. The bar turns red for invalid patterns and shows the exact JavaScript error message below it. Use the lettered flag toggles next to the bar: g (global — find all matches), i (case-insensitive), m (multiline — ^/$ match line boundaries), s (dot-all — . matches newlines), u (unicode mode).
  2. 2
    Paste your test string and see live highlightsType or paste any text into the large Test String editor below the pattern bar. Every match is highlighted inline in real time as you type — no button needed. The match count appears in the header stat badge. If no matches highlight, check your flags (try enabling the g flag) and verify special characters are properly escaped — a literal dot is \., not ..
  3. 3
    Use a preset to load a real-world pattern instantlyClick any button in the Presets bar — Email, URL, IPv4, Hex Color, ISO Date, US Phone, HTML Tag, JWT, Markdown Bold, or CSS Class. Each preset loads the pattern, the appropriate flags, and a matching sample test string simultaneously, giving you a working example you can then modify for your own needs.
  4. 4
    Inspect capture groups in the tableWrap any part of your pattern in parentheses (…) to create a capture group. The Capture Groups panel on the right shows every match as a row, with each group value in its own column. Use named groups (?<year>\d{4}) to get descriptive column headers instead of $1, $2. This makes complex multi-group patterns much easier to read and debug than in the browser console.
  5. 5
    Preview a replace operation and copy the patternSwitch to the Replace tab in the bottom-left panel. Enter a replacement string using $1, $2, or $<name> group references — the transformed output appears immediately, matching exactly what JavaScript's string.replace(regex, replacement) would produce. Click the copy icon at the right edge of the pattern bar to copy the full regex in /pattern/flags format, ready to paste directly into your JavaScript code.

Real-world uses

Common Use Cases

Test an email, URL, or phone validation regex before adding it to your form
Paste your pattern and a list of test inputs — valid addresses, edge cases, and deliberate invalid strings. The live highlighting immediately shows which strings match and which don't, so you can see false positives and missed cases before the pattern goes into production form validation code.
{}
Debug capture groups without console.log
Add parentheses around the parts you want to capture and the table shows every match with each group in its own labelled column. Named groups like (?<year>\d{4}) use the name as the column header instead of Group 1, Group 2 — far more readable than destructuring match results in the console.
Preview a string.replace() before writing the code
Switch to Replace mode, enter your replacement string using $1, $2, or $<name> group references, and see the full transformed output immediately. Confirm the replace logic works exactly as expected before pasting it into your codebase.
Extract fields from log lines and error messages
Write a pattern to pull timestamps, IP addresses, error codes, or request paths out of server logs, access logs, or stack traces. Named capture groups make log field extraction self-documenting — the group name tells you what each captured piece represents. Compare log output before and after with our Diff Checker.
Check that your allow-list pattern doesn't let through unexpected input
Test both valid inputs and deliberately crafted edge cases — special characters, unicode, empty strings, leading/trailing whitespace — to confirm your pattern's boundary conditions. Seeing mismatches highlighted inline is faster than running unit tests for each case.
Learn how lookaheads, lookbehinds, and flags actually behave
Load any preset, modify the pattern, and watch the highlights change in real time. This is the fastest way to internalize how (?=…) lookaheads, (?<=…) lookbehinds, the m multiline flag, and the s dot-all flag actually work — no documentation tabs, just edit and see. Validate JSON captured by your pattern with our JSON Formatter.

Got questions?

Frequently Asked Questions

Paste your pattern and test string here. Matches are highlighted inline in real time — if nothing highlights, the pattern doesn't match. If the highlights are in the wrong places, the pattern needs adjustment. Check: do you need the g (global) flag to find all matches instead of just the first? Does your pattern escape special characters correctly (a literal dot is \., not .)? Is the m (multiline) flag needed if ^ and $ should match at line boundaries? The error bar below the pattern input shows any syntax errors with the exact browser message.

Wrap the part of the pattern you want to capture in parentheses. For example, (\d{4})-(\d{2})-(\d{2}) on "2024-07-15" creates three groups for year, month, and day. The Capture Groups table shows every match as a row with each group value in its own column. Use named groups for readability: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) shows "year", "month", "day" as column headers instead of 1, 2, 3.

Switch to the Replace tab and enter your replacement template using $1, $2 (numbered groups) or $<name> (named groups). The result shows the full output string after all matches are replaced — equivalent to what JavaScript's string.replace(regex, replacement) would produce. $& inserts the full match, and $` / $' insert the text before/after each match. Verify the output is correct before putting it in your code.

g (global) finds all matches instead of stopping after the first — needed for the capture table to show more than one result. i (case-insensitive) ignores letter case. m (multiline) makes ^ and $ match at the start/end of each line instead of the whole string. s (dot-all) makes . match newline characters — by default . skips them. u (unicode) enables Unicode code point matching and \p{} property escapes like \p{Letter} or \p{Emoji}.

The error bar shows the exact browser error message. Common causes: unescaped special characters (a literal dot needs \., parentheses need \(\)), unclosed groups (an opening ( without a closing )), invalid escape sequences (\e is not valid in JS regex), and bad quantifier syntax ({2,1} where min is greater than max). The browser error message usually names the exact problem — read it carefully, it's more specific than it looks.

Lookahead (?=…) asserts the position is followed by a pattern without including it in the match — \d+(?= dollars) matches numbers followed by " dollars" but the match result doesn't include " dollars". Negative lookahead (?!…) matches when the position is NOT followed by the pattern. Lookbehind (?<=…) asserts the position is preceded by a pattern — (?<=\$)\d+ matches digits that follow a $ sign. Negative lookbehind (?<!…) matches when NOT preceded. Both lookbehind types are supported in all modern browsers (ES2018+).

Yes — paste any multiline text. By default, ^ and $ match only the start and end of the entire string, and . doesn't match newlines. Enable m (multiline) to make ^ and $ match at the start and end of each line. Enable s (dot-all) to make . match newline characters. Both flags can be combined — patterns that span multiple lines often need both m and s.

This uses JavaScript's native browser RegExp engine — the same engine running in Chrome, Firefox, Safari, and Edge. Patterns must be valid ECMAScript syntax. PCRE-only features like \K (keep-out), atomic groups (?>…), possessive quantifiers, and conditional patterns are not supported. ECMAScript features including named capture groups (?<name>…), lookbehind assertions, and Unicode property escapes \p{} with the u flag are fully supported in all modern browsers.

Click the copy icon at the right edge of the pattern bar. It copies the pattern in /pattern/flags format — for example /^\d{4}-\d{2}-\d{2}$/gm — ready to paste directly into JavaScript. For new RegExp(pattern, flags), remove the surrounding slashes and pass the flags separately.

Email (RFC 5321 validation), URL (http/https with optional path and query), IPv4 (four 0–255 octets), Hex Color (3-digit and 6-digit with optional #), ISO 8601 Date (YYYY-MM-DD), US Phone (various formats with optional country code), HTML Tag (opening tags with attributes), JWT (three Base64URL segments separated by dots), Markdown Bold (text and __text__), and CSS Class (valid CSS identifier). Each loads the pattern, appropriate flags, and a sample test string.