How to test a regular expression
- 1.
Enter the pattern
Type the expression without slashes, e.g. (\d{4})-(\d{2}), and switch on the flags you need (g, i, m, s, u, y, d).
- 2.
Paste the test text
Matches are highlighted as you type, and the table lists each match with its position and capture groups.
- 3.
Preview a replacement
Enter a replacement such as $2-$1 or $<name> to see the result of String.replace().
- 4.
Start from a ready pattern
Use the pattern library for emails, URLs, dates and common Polish formats as a starting point.
JavaScript regex flags
| Flag | Name | Effect |
|---|---|---|
| g | global | find all matches, not just the first |
| i | ignoreCase | case-insensitive matching |
| m | multiline | ^ and $ match at the start and end of every line |
| s | dotAll | the dot also matches newline characters |
| u | unicode | full Unicode support, e.g. \p{L} for any letter |
| y | sticky | match only at lastIndex |
| d | hasIndices | return start and end positions of groups |
In JavaScript \w and \b only cover ASCII letters, so “é”, “ü” or “ł” count as non-word characters. To match words in any language, use the u flag with \p{L}, for example [\p{L}\p{M}]+.
Capture groups, named groups and replacements
Parentheses ( ) create capture groups numbered from 1. A named group looks like (?<name>…). In the replacement you refer to them as $1 or $<name>, while $& inserts the whole match.
For example, the pattern (?<year>\d{4})-(\d{2})-(\d{2}) with the replacement $3/$2/$<year> turns “2026-03-15” into “15/03/2026”. A non-capturing group is written (?:…), a lookahead (?=…), a negative lookahead (?!…) and a lookbehind (?<=…). The results table shows every group for every match, with “-” for groups that did not participate.
Pattern library
The library at the bottom of the tool contains tested patterns for an email address, an http(s) URL and a DD.MM.YYYY date, plus formats you meet when dealing with Polish data: postal code (\d{2}-\d{3}), PESEL national ID (11 digits), NIP tax ID (with or without hyphens and the PL prefix), phone numbers with +48 and the Polish IBAN. Each one comes with a sample text, and every pattern is covered by automated tests with valid and invalid examples.
A regex checks only the format. It cannot compute checksums (PESEL, NIP, IBAN mod 97), and it does not know that 31.02 does not exist. For real validation, combine the regex with code, or use a dedicated validator such as the IBAN validator.
Catastrophic backtracking (ReDoS)
Some patterns, such as (a+)+$ run against “aaaaaaaaaaaaaaaaaaaaaaaaaaab”, make the number of matching attempts grow exponentially and can hang the browser or a server. ReDoS attacks exploit exactly this. This tester runs matching in a separate thread (a Web Worker) with a 2-second limit. When the limit is exceeded, the worker is terminated and you see a warning instead of a frozen tab. Avoid nested quantifiers and overlapping alternatives such as (a|a)*, and prefer specific character classes like [^"]* over .*.
Frequently asked questions
Which regex engine does the tester use?
+
Why does \w not match accented letters?
+
Why does my pattern freeze or time out?
+
How do I use named groups in the replacement?
+
Can a regex validate an email address completely?
+
Is my text sent to a server?
+
Updated: