Regex Tester
Test regex patterns with live matching
Regex Syntax Quick Reference
Regular expressions are a mini-language for describing text patterns. The core building blocks:
.— Any character except newline\d/\D— Digit / non-digit\w/\W— Word character ([A-Za-z0-9_]) / non-word\s/\S— Whitespace / non-whitespace^/$— Start / end of string (or line in multiline mode)*/+/?— 0+, 1+, 0 or 1 repetitions (greedy by default){n,m}— Between n and m repetitions[abc]— Character class;[^abc]negates it(group)— Capturing group;(?:group)is non-capturinga|b— Alternation: matchesaorb
Flags
g— Global: find all matches, not just the firsti— Case-insensitivem— Multiline:^/$match line boundariess— Dotall:.matches newlines toou— Unicode mode: enables full Unicode matching including surrogate pairs
Greedy vs. Lazy
Quantifiers (*, +, {n,m}) are greedy by default — they consume as much as possible. Add ? to make them lazy: .*? matches as little as possible. This matters most when matching delimited content like HTML tags: <.+> will match from the first < to the last > in the string, while <.+?> stops at the first closing >.
Lookahead and Lookbehind
(?=...) is a positive lookahead — asserts what follows without consuming it. (?<=...) is a positive lookbehind. Their negative counterparts are (?!...) and (?<!...). These are useful for matching text only when it's preceded or followed by a specific pattern without including that pattern in the match itself.