Regex Tester
Test regular expressions with live highlighting.
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
g— global. Find all matches, not just the first. You almost always want this when testing.i— case-insensitive./cat/imatches "cat", "Cat", "CAT".m— multiline. Makes^and$match the start and end of each line, not the whole string.s— dotall. Makes.match newlines too. Useful when matching across lines.u— unicode. Treats the pattern as Unicode-aware. Necessary for matching emoji or non-ASCII text correctly.
The cheat sheet most people actually need
\d— a digit.\D— not a digit.\w— a word character (letter, digit, underscore).\W— not.\s— whitespace.\S— not whitespace..— any single character (except newline, unlesssflag).*— zero or more.+— one or more.?— zero or one.{3}— exactly 3.{3,5}— 3 to 5.{3,}— 3 or more.[abc]— one of these characters.[^abc]— none of these.[a-z]— range.[a-zA-Z0-9]— alphanumeric.(abc)— capture group.(?:abc)— non-capturing group.^— start of string (or line, withm).$— end.|— alternation.cat|dogmatches either.\b— word boundary. Matches the position between a word character and a non-word character.
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.