.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 classa|bAlternation (a or b)(?=…)Lookahead(?!…)Neg. lookahead(?<=…)LookbehindRegex Tester Online Free — Live Match Highlighting, Capture Groups & Replace Preview
What's included
Features
About this tool
Test JavaScript Regex Online — See Matches Instantly as You Type
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
- 1Type 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). - 2Paste 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
gflag) and verify special characters are properly escaped — a literal dot is\., not.. - 3Use 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.
- 4Inspect 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. - 5Preview 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'sstring.replace(regex, replacement)would produce. Click the copy icon at the right edge of the pattern bar to copy the full regex in/pattern/flagsformat, ready to paste directly into your JavaScript code.
Real-world uses
Common Use Cases
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.