How to test a regex
Type the pattern between the slashes, choose your flags and paste the test text. Matches are highlighted in alternating colors, and the table shows the position and groups of each one. If the pattern has a syntax error, the engine's message appears below the field.
Groups, replacement and examples
Capture groups let you extract parts of a match, like the day, month and year of a date. In the replacement field, $1 inserts group 1, $& the whole match and $<name> a named group. The ready-made examples show these features applied to common cases.
Common mistakes
Forgetting to escape special characters like . ? + ( ) [ ], using greedy .* when you meant .*?, forgetting the g flag and expecting every match, and trusting a regex to validate everything: a correctly formatted ID number can still have invalid check digits, and email addresses have rules a simple pattern does not cover.
Privacy
The test runs entirely in your browser. Your text and pattern are not sent to any server. For other text tools, see the text diff checker.
Frequently asked questions
What is a regular expression (regex)?
It is a pattern that describes a set of strings. It is used to search, validate and replace text, such as finding every email in a document or checking that a field has the right format.
Which flags can I use?
g (all matches), i (ignore case), m (^ and $ work per line), s (dot also matches line breaks) and u (Unicode mode, needed for \p{L} and emoji). Without g, only the first match is shown.
How do I use capture groups in the replacement?
Put parts of the pattern in parentheses and use $1, $2 and so on in the replacement field. With named groups, like (?<year>\d{4}), use $<year>. $& inserts the whole match.
Does this tester work for Python, PHP or Java?
It uses the JavaScript engine. Basic syntax is similar across most languages, but there are differences, such as lookbehind support, named groups and flags. Test in the target environment when the pattern is complex.
Why was my test stopped for taking too long?
Some patterns, like (a+)+$, cause catastrophic backtracking on certain inputs and can take very long. The tester runs the regex in the background and stops it after 1.5 seconds so the page does not freeze. Make the pattern more specific or avoid nested repetition.