Regex Tester: Test JavaScript Regular Expressions Safely
By FindMySum · Last reviewed
This regex tester shows every match of a JavaScript regular expression in your text as you type: where each match starts, what each capturing group and named group caught, what a replacement would produce and how the text would split. The pattern and the text stay in your browser.
How to use the tool
- Type the pattern without the surrounding slashes. The flags you pick appear after the closing slash, so
/\d+/gis the pattern\d+with the g flag. - Paste the text to search into Test text. Matches are marked in alternating colours, and each one is listed with its groups below.
- To try a substitution, type a replacement such as
$2-$1or$<day>/$<month>; the result appears under it. - Open Split preview to see what
text.split(pattern)would return.
A worked example
The example pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) looks for ISO dates. In the invoice text it finds three: 2026-11-12, 2026-12-12 and 2026-12-01. For the first, group 1 (year) is 2026, group 2 (month) is 11 and group 3 (day) is 12. The replacement $<day>/$<month>/$<year> rewrites each date day-first, so the text reads "issued 12/11/2026". The number 1042 isn't matched, because it has no hyphens after it.
Common mistakes
Forgetting to escape special characters. A dot matches any character, so 1.5 also matches 105. Write 1\.5 to match a literal dot. The same goes for ( ) [ ] { } * + ? ^ $ | \ and /.
Greedy quantifiers that swallow too much. <.+> on <b>bold</b> matches the whole string, because .+ takes as much as it can. Use the lazy form <.+?> or a negated class <[^>]+>.
Expecting ^ and $ to match each line. Without the m flag they only match at the very start and end of the text.
Copying a pattern from another language. Python's (?P<name>…) and PCRE's possessive a++ are syntax errors in JavaScript; the tester reports them so you can rewrite them.
To compare two versions of a text instead of searching one, use the diff checker.