How to test a regular expression online (JavaScript regex)
A regular expression (regex) is a compact search pattern. Regex tester shows exactly what it matches in your text, using JavaScript syntax.
Steps
- Type the pattern without surrounding slashes, for example
\d+. - Add flags:
gfinds all matches,iignores case,mmakes^and$work on every line. - Paste test text on the left.
- Read the matches: each is listed with its position, numbered groups and named groups.
Handy patterns
- Whole numbers:
\d+ - Simple email check:
[\w.+-]+@[\w-]+\.[\w.]+(good enough for filtering, not for strict validation) - Hex colour:
#(?:[0-9a-fA-F]{3}){1,2}\b - Named group:
#(?<id>\d+)matches#42and reportsid = "42".
Groups
Round brackets capture part of a match. (\d{4})-(\d{2}) on 2026-10 gives group 1 2026 and group 2 10. Add ?: to group without capturing.
Common mistakes
- Forgetting
g, so only the first match shows. - Not escaping a dot:
.means any character; write\.for a literal dot. - Greedy matching:
<.+>grabs from the first<to the last>. Use<.+?>for the shortest match. - Using syntax from another language. This tool follows JavaScript, so some features (such as possessive quantifiers) do not exist.
Warning
Poorly written patterns with nested repetition can take extremely long on large text (catastrophic backtracking) and freeze the tab. Reload the page if that happens and simplify the pattern.