How to test a regular expression
Enter a regex and some text — the tester instantly shows every match with its position and capture groups. It uses the JavaScript engine (RegExp), so results match browsers, Node.js and TypeScript.
Example: \b\d{2}-\d{3}\b finds Polish postcodes. In “Warsaw 00-950, Kraków 30-001, phone 123-456-789” it matches 00-950 and 30-001 and skips parts of the phone number thanks to the word boundaries \b.
Syntax essentials
| Pattern | Meaning |
|---|---|
| \d, \w, \s | digit, word character, whitespace |
| . | any character (except newline, unless flag s) |
| *, +, ? | 0 or more, 1 or more, 0 or 1 |
| {2}, {2,4} | exactly 2, from 2 to 4 |
| [a-z], [^0-9] | character range, anything except digits |
| ^, $ | start and end of text (or line with flag m) |
| ( ), (?: ) | capturing and non-capturing group |
| a|b | a or b |
Flags
- i — case-insensitive.
- m — ^ and $ match the start and end of each line.
- s — dot matches newlines too.
- u — Unicode mode: correct handling of emoji and classes like \p{L} (any letter in any alphabet).
Frequently asked questions
How do I match accented letters?
[a-z] doesn’t include them. With the u flag, use \p{L}, which matches any letter in any alphabet.
Why does my regex work here but not in PHP or Python?
The syntax is similar but not identical — named groups, lookbehind and Unicode classes differ between engines. This tester uses the JavaScript engine.