Regex tester
Write a regular expression and see every match highlighted as you type, with its capture groups. Try find and replace, or start from a common pattern. Uses your browser's JavaScript regex engine, and nothing is uploaded.
Match details
Common patterns
How to test a regular expression
- Type the pattern between the slashes, or paste a whole literal like
/\d+/gand the flags are picked up for you. - Paste your test text. Matches are highlighted as you type, and each one is listed with its position and capture groups.
- Turn on Replace to preview
String.replacewith references like$1or$<year>, then copy the result or the regex as code.
Regex cheat sheet
- Characters:
.any character,\ddigit,\wletter, digit or _,\swhitespace,\D \W \Stheir opposites,[abc]one of,[^abc]none of,[a-z]a range. - Anchors:
^start,$end (of each line withm),\bword boundary. - Quantifiers:
*0 or more,+1 or more,?optional,{3}exactly 3,{2,5}2 to 5. Add?to make them lazy:.*?. - Groups:
(abc)capture,(?:abc)group without capturing,(?<name>abc)named group,\1back-reference,a|beither. - Lookaround:
(?=abc)followed by,(?!abc)not followed by,(?<=abc)preceded by,(?<!abc)not preceded by. - Unicode (with
uorv):\p{L}any letter in any language,\p{Emoji},\u{1F600}.
Flags
g finds every match instead of the first. i ignores case. m makes ^ and $ match at each line. s lets . match line breaks. u enables full Unicode (code points, \p{…}). v is the newer Unicode mode with set operations like [\p{L}--[a-z]]. y (sticky) matches only at lastIndex. d records the start and end of every group, shown in the match details.
Catastrophic backtracking
Patterns with nested quantifiers, like (a+)+$ or (.*,)*, can take exponential time on text that almost matches. That freezes browsers and can take down servers (ReDoS). This tester runs every regex in a background worker and stops it after 1.5 seconds, so a slow pattern shows a warning instead of hanging the page. Rewrite such patterns to remove the nesting or make the alternatives exclusive.
Questions
Which regex flavor does this use?
JavaScript (ECMAScript), using your browser's own engine, so results match what new RegExp() and String.match() do in your code. Most syntax is shared with PCRE, Python and Java, but some features differ (for example possessive quantifiers and atomic groups don't exist in JavaScript).
Why does my regex only find the first match?
Turn on the g (global) flag. Without it, JavaScript stops at the first match.
How do I match across several lines?
Use the s flag so . matches line breaks, or [\s\S] to match any character. Use the m flag if you want ^ and $ to match at the start and end of each line.
How do named groups work?
Write (?<name>...) to capture into a named group. In the match details it appears as <name>, in replacements use $<name>, and in code read it from match.groups.name.
How do I escape special characters?
Put a backslash before any of . * + ? ^ $ { } ( ) | [ ] \ / to match it literally, for example \. for a dot. Inside new RegExp("...") strings, double the backslashes.
Is my text uploaded anywhere?
No. Patterns and text stay in your browser. The regex runs in a local Web Worker so it can be stopped if it hangs.
Why was my pattern stopped?
It ran longer than 1.5 seconds, which almost always means catastrophic backtracking from nested quantifiers like (a+)+ or (.*)*. The same pattern could freeze a user's browser or a server, so it's worth fixing.