Regex Tester

Test regular expressions with live highlighting.

/ /
0 matches
Matches will be highlighted here
No matches yet

What regex is for

A regular expression is a tiny language for describing patterns in text. Instead of asking "is this exact string equal to that one?" you ask "does this text contain something that looks like a phone number, an email address, a URL, a sequence of three digits followed by a dash"? Regex is one of the most leveraged tools in the working programmer's belt — ten characters of pattern can replace a hundred lines of imperative parsing code.

This tester runs your pattern against your input live. Every keystroke re-runs the match and updates the highlighted matches and the per-match details (full match, capture groups, position). It uses your browser's native JavaScript regex engine, so the syntax and edge cases match what you'd see in String.prototype.match or RegExp.

The flags, briefly

The cheat sheet most people actually need

Things that bite people

Greedy by default

.* matches as much as it can. Given the input <b>hi</b> <i>world</i>, the pattern <.*> matches the whole thing — not just the first tag. Add a ? after the quantifier to make it lazy: <.*?> matches each tag separately.

Don't parse HTML with regex

This is the classic warning. HTML is not a regular language; nested tags, comments, and CDATA blocks all break naive patterns. For real HTML use a parser. Regex is fine for stripping a known tag from known-clean input, but the moment the input gets messy, you'll spend more time fixing the regex than you would have writing a parser call.

Email validation

The "official" regex for matching RFC 5322 email addresses is several hundred characters long, and even it doesn't cover every legal address. For practical purposes, /^.+@.+\..+$/ catches obvious typos and that's all you actually need; real validation happens by sending a confirmation email.

Backtracking and ReDoS

Some patterns can take exponential time on certain inputs — a category of vulnerability called Regular Expression Denial of Service. The pattern (a+)+$ against the string aaaaaaaaaaaaaaaaX can take seconds or minutes to fail. If a regex runs in user-facing code over user-supplied input, avoid nested quantifiers around the same substring.

Suggested workflow

Paste in a representative chunk of real input first. Then build the pattern incrementally: get one match working, expand to handle the variations, add anchors and groups last. Testing as you go beats writing a long regex and then debugging it.