Regular expressions are powerful but famously easy to get wrong, and a tiny mistake can match far too much or nothing at all. This free regex tester lets you build and debug a pattern against your own sample text and see the results instantly. Matches are highlighted live as you type, and a table lists every match with its position and each capture group, including named groups like (?<year>\d{4}). Toggle the common flags (global, case-insensitive, multiline, dotAll and Unicode) and try a replace pattern using $1 or $<name> to preview a find-and-replace before running it in your code or editor. It uses your browser's own JavaScript regex engine, so results match exactly what you'll get in JavaScript, TypeScript and Node.js. Other flavours such as Python, PCRE (PHP) and Java share most syntax but differ in places like lookbehind support and named group syntax, so double-check advanced patterns there. There's also a short cheat sheet below and a few ready-made examples for emails, URLs and dates. It's handy for checking patterns that ChatGPT or another AI wrote for you, too. Nothing you type leaves your device.
Test a regular expression
Highlighted matches
Match details
Replace preview
How to use the regex tester
- Type your pattern without the surrounding slashes.
- Tick the flags you need. Use g to find every match.
- Paste sample text. Matches highlight instantly.
- Check the group table, then try a replacement.
Regex cheat sheet
| \d \w \s | Digit, word character, whitespace |
| . | Any character except newline (unless s flag) |
| * + ? {2,5} | 0+, 1+, 0 or 1, between 2 and 5 |
| ^ $ \b | Start, end, word boundary |
| [abc] [^abc] | Any of / none of these characters |
| ( ) (?: ) (?<n> ) | Capture, non-capture, named group |
| (?= ) (?! ) | Lookahead, negative lookahead |
FAQ
Which regex flavour does this use?
JavaScript (ECMAScript), via your browser’s engine. Results match JavaScript, TypeScript and Node.js exactly.
Will my pattern work in Python or PHP?
Usually, for common syntax. Differences include named groups (Python uses (?P<name>…)) and some lookbehind and Unicode features.
Why does my pattern only find one match?
Turn on the g (global) flag to find all matches.
Can a regex freeze the page?
Patterns with nested repetition, like (a+)+, can be extremely slow on some inputs. That’s called catastrophic backtracking; simplify the pattern if the page lags.
Comments
Post a Comment