Regex Tester
Test a regular expression against text and see every match highlighted.
Match count
—
About this tool
Type a regular expression and some test text to see every match highlighted as you type, with a running match count. Toggle flags to change matching behaviour. Everything runs on JavaScript's native regex engine in your browser — nothing is sent anywhere.
The flags.
g— global: find every match, not just the first. You almost always want this when testing.i— case-insensitive:catalso matchesCatandCAT.m— multiline:^and$match at the start and end of each line, not just the whole string.s— dotall:.also matches newline characters.u— unicode: needed for\p{...}property escapes and correct handling of characters outside the basic plane.
A quick syntax refresher. \d a digit, \w a word character, \s whitespace; . any character (except newline unless s); * zero or more, + one or more, ? optional, {2,4} a count range; [abc] a set, [^abc] a negated set; (...) a capturing group, (?:...) non-capturing; | alternation; ^ and $ anchors.
Common gotchas. Quantifiers are greedy by default — <.+> against <a><b> matches the whole thing; add ? (<.+?>) to make it lazy. A dot inside a character class is literal, so [.] or \. both mean a full stop. This engine is JavaScript's, which differs from PCRE, Python's re, and Go's regexp in some lookbehind and escape details.
Don't parse HTML or email addresses with regex for anything that matters. The classic "email regex" rejects valid addresses and accepts invalid ones; a real address is validated by sending mail to it. Regex is for quick extraction and validation of simple, well-defined shapes.
Catastrophic backtracking. Patterns with nested quantifiers like (a+)+$ can hang the engine on certain inputs. If matching freezes, simplify the pattern rather than feeding it more text.
To turn matched text into a clean URL slug, use the slug generator. To check an address against the common rules, use the email validator. For scheduling syntax, the cron expression explainer does the same live-explanation job for crontab lines.
Frequently asked questions
- What happens if my pattern is invalid?
- A hint explains the problem — an unclosed group or character class, a dangling quantifier — instead of silently showing no matches.
- Why do I need the "g" flag to see all matches?
- Without it, JavaScript's engine reports only the first match. The global flag tells it to scan the whole string, which is what you usually want when testing.
- Does it show capture groups?
- The highlighted view marks whole matches. It's built for confirming what a pattern matches in context rather than inspecting individual groups.
- Is this the same regex as Python or PHP?
- It's JavaScript's engine. The core syntax is shared, but details around lookbehind, named groups, and some escapes differ between JavaScript, PCRE, and Python's
re. - Can I test a pattern against multiple lines?
- Yes. Paste multi-line text, and add the
mflag if you want^and$to anchor to each line. - The page froze while I was typing a pattern — why?
- Some patterns with nested quantifiers backtrack exponentially on certain input. Rewrite the pattern to avoid overlapping repetition.