Home/Tools/Text & developer utilities
Regex Tester
Matches highlight live. JavaScript regex syntax.
Building a pattern piece by piece
The sample pattern matches email addresses. Reading it left to right:
- [a-z0-9._%+-]+ — one or more of those characters, the local part before the at sign
- @ — a literal at sign
- [a-z0-9.-]+ — the domain
- \. — an escaped dot, meaning a literal dot rather than "any character"
- [a-z]{2,} — at least two letters, the top-level domain
The pieces worth memorising
- . any character \d digit \w word character \s whitespace
- * zero or more + one or more ? optional {2,5} between two and five
- ^ start $ end \b word boundary
- [abc] any of these [^abc] none of these
- (...) capture group (?:...) group without capturing | or
Greedy by default, which surprises everyone once
Quantifiers take as much as they can. Against <b>bold</b>, the pattern <.+> matches the whole string, not just the first tag, because .+ grabs everything and then backtracks only as far as it must.
Adding a question mark makes a quantifier lazy: <.+?> matches each tag separately.
Catastrophic backtracking
Nested quantifiers such as (a+)+$ can take exponential time on a non-matching string, hanging the browser or the server. This has caused real outages, and it is a denial-of-service vector when a pattern is applied to user input.
If a pattern is slow, look for a quantifier inside a group that is itself quantified.
What not to use a regex for
Parsing HTML, JSON or any nested structure. Regular expressions fundamentally cannot count nesting depth, so every attempt works on your examples and fails on real input. Use a parser.
Email validation is the other classic. The fully correct pattern from the specification is thousands of characters long and still accepts addresses that do not exist. Check for an at sign, then send a confirmation message.
Common uses
- Extracting values from log lines or scraped text.
- Validating a format such as a postcode or reference number.
- Search and replace across a file in an editor.
- Testing a pattern before committing it to code.
Questions people ask
Why does my pattern match too much?
Quantifiers are greedy by default. Add a question mark — .+? instead of .+ — to make them lazy.
What does \\b do?
Matches a word boundary, the position between a word character and a non-word character. Useful for matching whole words.
Why is my regex extremely slow?
Probably catastrophic backtracking from a quantifier inside a quantified group, such as (a+)+. It can take exponential time and has caused real outages.
Can I parse HTML with a regex?
No. Regular expressions cannot count nesting depth, so any attempt works on examples and fails on real input. Use a parser.
Should I validate emails with a regex?
Only loosely. The fully correct pattern is thousands of characters and still accepts addresses that do not exist. Check for an at sign and send a confirmation message.
Your text stays in the page
This matters more here than on most tools. People paste API keys into hash generators, customer data into CSV converters, contract wording into diff checkers and configuration into JSON validators. Almost every site offering these sends your input to a server to process it.
Nothing here is transmitted. The work happens in your browser, this site is static files with no server behind it, and the about page lists every request the site makes, read live from your own browser so you can check rather than trust.