Regex Tester (JavaScript)
Highlighted matches
About this tool
Type a pattern, paste some text, and see every match highlighted as you type. The details table lists each match with its position, numbered capture groups and named groups, and you can test a replacement string before you put it in code.
Everything runs in your browser. The text you paste is never sent to a server.
How it works
- This uses your browser's own JavaScript (ECMAScript) regex engine, so results match what
new RegExp()gives you in JavaScript and Node.js. - Other languages differ. Python, PCRE (PHP, grep -P) and Java support features JavaScript does not, such as possessive quantifiers, atomic groups and inline flags like
(?i). Test those patterns in their own language before you rely on them. - Without the
gflag only the first match is highlighted, and a replacement changes only the first match, exactly as in JavaScript. - Zero-length matches (for example
^or\b) are shown as a red bar at their position. - The table shows at most 1,000 matches; the highlighting stops there too.
- Look-behind (
(?<=x)) and named groups ((?<name>x)) work in current versions of Chrome, Edge, Firefox and Safari. Older browsers may report a syntax error.
Quick reference
| Token | Meaning | Token | Meaning |
|---|---|---|---|
\d \w \s | digit, word character, whitespace | ^ $ | start / end of input (or line with m) |
\D \W \S | the opposites | \b | word boundary |
[abc] [^abc] | any of / none of | (x) (?:x) | capturing / non-capturing group |
x* x+ x? | 0+, 1+, 0 or 1 (greedy) | (?<n>x) | named group |
x*? x+? | lazy versions | x(?=y) x(?!y) | look-ahead (must / must not follow) |
x{2,4} | 2 to 4 times | (?<=y)x (?<!y)x | look-behind |
\p{L} | Unicode letter (needs u) | \1 \k<n> | back-reference |
FAQ
Q. The page froze while I was typing a pattern.
A. Some patterns, such as (a+)+$, take exponential time on certain text. This is called catastrophic backtracking, and the tab cannot be interrupted while it runs. Close the tab if needed, and use lazy quantifiers or more specific character classes. Do not use such patterns on untrusted input in production.
Q. Why does my pattern work here but not in Python or PHP?
A. Named groups are written (?<name>x) here and (?P<name>x) in Python. Escaping and delimiter rules also differ in each language. Check the flavor notes above.