Regular expressions are difficult to get right by reading alone — the difference between a pattern that works and one that quietly matches too much is often a single character. Testing against real sample text, with matches highlighted as you type, is the only reliable way to build one.
How to use the Regex Tester
- Enter your regular expression
- Paste sample text that represents the real data, including edge cases
- Set the flags you need — g for all matches, i for case-insensitive, m for multiline
- Check the highlighted matches and the match count before using the pattern
The pieces you will use most
\ddigit ·\wword character ·\swhitespace. Capitalised versions negate:\Dis any non-digit.+one or more ·*zero or more ·?zero or one.{3}exactly three ·{2,5}between two and five.^start of string ·$end of string.[abc]any one of these ·[^abc]anything but these.(…)capture group ·(?:…)group without capturing.
Greedy matching, the classic trap
Quantifiers are greedy by default — they match as much as possible. Run <.+> against <b>bold</b> and it matches the entire string, not just the opening tag, because .+ consumes everything and then backtracks only enough to find a final >.
Adding ? makes a quantifier lazy: <.+?> matches just <b>. When a pattern matches far more than you expected, greediness is almost always why.
The flags matter too: g finds every match rather than stopping at the first, i ignores case, and m makes ^ and $ match at line boundaries instead of only at the start and end of the whole string.
Frequently asked questions
Why does my pattern match more than expected?
Greedy quantifiers. By default + and * take as much as they can. Add ? to make them lazy — .+? instead of .+ — and they take as little as possible.
How do I match a literal dot or question mark?
Escape it with a backslash: \. and \?. The characters . * + ? ( ) [ ] { } | ^ $ \ all have special meaning and need escaping to match literally.
Which regex flavour does this use?
JavaScript's, since it runs in your browser. It is close to PCRE for everyday patterns, but lookbehind support and some Unicode property escapes differ from Python or PHP.
Can I use this to validate email addresses?
You can match the common shape, but fully validating email by regex is not practically possible — the specification permits forms almost nobody implements. Match loosely and confirm by sending a verification email.