How to use the regex tester
- Start from a common pattern in the list, or type your own between the slashes.
- Toggle flags with the buttons;
g(global) is usually what you want for testing. - Edit the test text. Matches are highlighted in alternating colours.
- Read “What this pattern means” to check that each token does what you intended.
- Turn on the replacement preview to try a replacement string.
- Copy the JavaScript snippet at the bottom into your code.
The match table lists each match with its start and end position and the value of every group. Named groups are shown by name.
How it works
The pattern is compiled with your browser’s own RegExp engine, so results match what your JavaScript code will do. Matching runs in a Web Worker, a separate thread. If it doesn’t answer within 1.5 seconds, the worker is terminated and restarted, and you’re told why. Zero-length matches (such as \b or x*) are handled by stepping forward one character (one code point with the u flag), so the search always finishes. Results stop at 1,000 matches.
Worked examples
Example 1: reformatting dates
The default pattern (?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>…) finds ISO dates and rejects month 13. With the replacement $<day>.$<month>.$<year>, 2026-10-05 becomes 05.10.2026, the format used in Germany.
Example 2: finding repeated words
Load Repeated word: \b(\w+)\s+\1\b with the i flag. It finds “is is” and “the the” in the sample, because \1 must repeat whatever group 1 matched.
Example 3: validating slugs line by line
Load URL slug with the m flag. ^ and $ then anchor each line, so my-blog-post and version-2-0 match while Another Post and trailing- don’t. Without m, the anchors apply to the whole text and nothing matches.
Writing better patterns
- Anchor validation patterns with
^…$, or a partial match will pass. - Prefer specific classes (
[^"]*) over.*, which is greedy and slow. - Use non-capturing groups
(?:…)when you don’t need the value. - Escape special characters (
. * + ? ( ) [ ] { } | \ ^ $) when you mean them literally.
Common mistakes
- Forgetting
gwhen you expect all matches. - Double escaping. In a JavaScript string,
"\\d"is needed; in a regex literal,/\d/is enough. The tester uses literal syntax. - Greedy matches across tags.
<.*>matches from the first<to the last>; use<[^>]*>. - Parsing HTML or JSON with regex. Use a real parser for nested structures.