Regex Tester
Paste a JavaScript regular expression without enclosing slashes, choose flags and supply sample text. Match mode highlights results and lists numbered or named capture groups with their UTF-16 offsets. Replace mode previews native JavaScript string replacement: keep a group with $1 or $<name>, keep the entire match with $&, or leave the replacement empty to remove matches. The g flag selects all matches; without it only the first match is replaced. Both workflows run in a disposable worker with a 1.5-second timeout. The match list shows up to 5,000 results, input text is limited to 2,000,000 characters, and replacement refuses an output above 2,000,000 characters or more than 5,000 substitutions instead of returning partial text.
Matches, groups and offsets appear here.
- Matches
- -
- Groups
- -
- Flags
- Engine
- JavaScript
Waiting for a pattern and some text.
d record where each match starts and ends · g find every match, not only the first · i ignore upper and lower case · m ^ and $ match at every line · s a dot also matches a newline · u read the text as unicode code points · v unicode sets, with set operations in classes · y match only where the last one left off
- both, with offsets
- listed by name
- stopped by timeout
Common questions
- Why does my pattern only find the first match?
- Because the g flag is not set. Flags are passed to the engine exactly as you type them, so a pattern without g stops at the first match here for the same reason it does in your code. Add g to the flags box and the rest appear, each with its own offset.
- What happens if my pattern takes forever?
- It is stopped. Every run is posted to a worker created for that run alone, with a 1.5 second timeout armed beside it, and when the timeout fires the worker is terminated. You get a message saying the run was stopped and why, and the page, your pattern and your sample text are all still there. Catastrophic backtracking cannot be spotted before it happens and cannot be interrupted from the inside, so killing the thread it runs on is the only reliable stop.
- Does it show named capture groups?
- Yes, by name and by number. The group names are read from the pattern rather than from a match, so a pattern with (?<user>...) still names user among its groups when nothing matched at all, which is exactly when you want to see it. A group that took no part in a match is shown as no match, which is a different thing from a group that matched an empty string.
- Is this the same regex engine as my code?
- It is the JavaScript engine of the browser you are reading this in, used as it is. Regular expression syntax and behaviour are set by the JavaScript language itself, so an answer here carries over to Node and to other browsers, apart from the newest flags an older engine may not have yet. It is not PCRE, Python re or Go RE2: possessive quantifiers, recursion and atomic groups are not JavaScript syntax, and a pattern that needs them is reported here as invalid.
- How much text can I paste in?
- Up to 2,000,000 characters in one pass, and the first 5,000 matches are listed. Both numbers are stated on screen when you reach them: past the text ceiling the tool says so and names the size that arrived, and past the match ceiling it says the list is the first 5,000 rather than passing a partial count off as the total.
- Does my pattern or my text leave the page?
- No. There is no upload and no account: matching runs in your browser, in a worker built from this page's own code. Your pattern, flags and text are kept in your browser's local storage so the page opens where you left it, and the Start over button on this page forgets them.
- How do I replace a capture group or keep part of a match?
- Switch to Replace and use $1 through $99 for numbered groups or $<name> for a named group. For example, (\w+), (\w+) with replacement $2 $1 changes Lovelace, Ada to Ada Lovelace. Captures that did not participate substitute empty text. Unknown numbered tokens remain literal; an unknown named token substitutes empty text only when the pattern has named groups.
- Can I remove special characters or whitespace?
- Yes. Use a pattern that matches the characters you want removed, select g and leave the replacement empty. [^A-Za-z0-9] removes everything except ASCII letters and digits, including spaces and non-ASCII letters. \s+ with a single space as replacement collapses whitespace, including line breaks. Choose Unicode property escapes with u or v when your rule should include letters outside ASCII.
- How do I insert a newline or a literal dollar sign?
- Type an actual line break in the replacement box. The two characters \n are literal replacement text, not an interpreted newline. $$ inserts a dollar sign, $& inserts the match, $` inserts the original prefix and the dollar-apostrophe token inserts the original suffix. Repeating prefixes or suffixes can make output grow rapidly; oversized results are refused before native substitution.
- Can I use Python, PCRE, RE2, editor macros or replacement callbacks?
- This page previews the browser JavaScript RegExp engine and a replacement string. It does not emulate another engine, edit files in an application, execute a replacement callback, increment numbers or change the case of captured text. Node and TypeScript commonly use JavaScript regex syntax, but engine versions and the surrounding program still need their own tests.
Matching uses your browser's own JavaScript regular expression engine, so what you see here is what your code will do. It runs in a disposable worker with a timeout, so a pattern that would hang the page is stopped and reported instead.