Regex Tester
Test JavaScript regular expressions live: highlighted matches, capture and named groups, flags, a replace preview and a cheat sheet. Safe from runaway patterns.
| # | Match | Position | Groups |
|---|---|---|---|
Cheat sheet
- .
- any character except a line break
- \d \w \s
- digit, word character, whitespace
- \D \W \S
- not a digit, word character, whitespace
- \b
- word boundary
- ^ $
- start / end of the text (of a line with m)
- [abc] [^abc]
- one of / none of these characters
- [a-z]
- a character in a range
- a|b
- a or b
- (…)
- capturing group
- (?<name>…)
- named group
- (?:…)
- group without capturing
- * + ?
- 0 or more, 1 or more, 0 or 1
- {2,5}
- between 2 and 5 times
- *? +?
- lazy: as few as possible
- (?=…) (?!…)
- followed by / not followed by
- (?<=…) (?<!…)
- preceded by / not preceded by
- $1 $<name>
- group in the replacement
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the Regex Tester
- 1 Type your regular expression and choose the flags.
- 2 Paste the text to test; matches are highlighted and listed with their groups.
- 3 Optionally preview a replacement, then copy the matches or the result.
About the Regex Tester
A regular expression is a pattern that describes text: \d+ matches a number, ^\s+ leading whitespace, [\w.+-]+@[\w-]+\.\w+ something that looks like an e-mail address. Regex is used for validation, searching, extracting data from logs and search-and-replace in editors and code.
This tester uses the JavaScript regex engine of your browser, the same flavor as in JavaScript, TypeScript and Node.js. Every match is highlighted in the text and listed with its position and groups, including named groups (?<name>…). With replace you see the result of text.replace() using $1, $<name>, $& and other replacement patterns.
Some patterns, like (a+)+$ on a long string, take exponentially long to fail (catastrophic backtracking). The tester runs your expression in a background worker and stops it after one second, so the page never freezes. Most syntax is shared with other flavors (PCRE, Python, Java), but lookbehind, named groups and flags differ in places.
Frequently asked questions
Which regex flavor is this?
JavaScript (ECMAScript) regex as implemented in your browser, including lookbehind, named groups and Unicode property escapes like \p{L} with the u flag.
Why does only the first match show?
Without the g (global) flag a regex stops after the first match. Turn on g to find all of them.
What do the m and s flags do?
m makes ^ and $ match at the start and end of every line; s lets . match line breaks too.
Why was my expression stopped?
It took more than a second, usually because of nested quantifiers such as (a+)+. Rewrite the pattern to be more specific.