Regex
Test a JavaScript regular expression against your own text. Matches are highlighted as you type, with every capture group, a replace preview, a list of the matches and a split. Nothing leaves your browser.
//g
Type a pattern to start.
/(?:)/gCommon patterns
Instructions
A tester for JavaScript regular expressions — the same engine your browser and Node use. Everything runs in your browser; the pattern and text are kept in this browser's local storage so they survive a reload.
- Type a pattern between the slashes. Leave out the slashes and flags — pick flags with the toggles below (
gis on by default). - Paste the text to test into Test text. Matches are highlighted as you type.
- Matches lists each match with its position and capture groups. Replace previews
text.replace(), List puts every match (or one group) on its own line, and Split showstext.split(). - Copy the result, or copy the pattern as a
/…/flagsliteral ready to paste into code.
Tips
- This is JavaScript's dialect. PCRE-only syntax such as possessive quantifiers (
a++), atomic groups(?>…)and inline flags(?i)is a syntax error here, and Python's(?P<name>…)is written(?<name>…). - Backslashes are typed once: write
\d, not the\\dyou would need inside a string passed tonew RegExp(). - Without
gonly the first match is found. Withoutm,^and$match only at the very start and end of the whole text, not at each line. - A pattern that runs longer than a second is stopped, so something like
(a+)+$cannot freeze the page. That usually means nested quantifiers are backtracking; make the inner part more specific. - A pattern that can match nothing (
a*,\b) shows empty matches as thin carets in the highlighted text. - Hit Example, then click a Common patterns chip, Load example, or one of the Replace, List and Split tabs to see it run on sample text.
Cheat sheet
| . | Any character except a line break (any at all with s) |
| \d \w \s | Digit, word character [A-Za-z0-9_], whitespace |
| \D \W \S | The opposite of each |
| \b \B | Word boundary, not a word boundary |
| ^ $ | Start / end of the text (of each line with m) |
| [abc] [^abc] [a-z] | One of, none of, a range |
| * + ? | 0 or more, 1 or more, 0 or 1 |
| {3} {2,} {2,5} | Exactly 3, 2 or more, 2 to 5 |
| *? +? ?? | Lazy — as few as possible |
| (…) | Capture group, $1 in a replacement |
| (?<name>…) | Named group, $<name> in a replacement |
| (?:…) | Group without capturing |
| \1 \k<name> | Backreference — the same text again |
| a|b | Either |
| (?=…) (?!…) | Followed by, not followed by |
| (?<=…) (?<!…) | Preceded by, not preceded by |
| \p{L} \p{Lu} | Unicode letter, upper-case letter (needs u or v) |