Regex Tester
Test regular expressions with real-time match highlighting and capture groups.
Tips
- Use named capture groups (?<name>...) for more readable regex.
- Use lazy quantifiers *? +? when you want the shortest match.
- Watch out for catastrophic backtracking with nested quantifiers like (a+)+.
- The multiline flag (m) makes ^ and $ match at line boundaries, not just string boundaries.
- Press Cmd+Enter to re-run the regex test.
Understanding Regular Expressions
Regular expressions (regex) are patterns for matching and manipulating text. Supported by virtually every language and editor, they let you search, validate, extract, and transform text with precision. The syntax looks cryptic initially but becomes powerful once you learn the fundamentals.
Core building blocks include literal characters (match themselves), character classes like [a-z] (any lowercase letter), quantifiers like * (zero or more), + (one or more), ? (zero or one), and anchors like ^ (start) and $ (end). Combining these describes complex patterns concisely.
Capture groups with parentheses () extract specific match portions. Named groups (?<name>...) improve readability. For example, (\w+)@(\w+)\.(\w+) on an email captures username, domain, and TLD as separate groups.
Flags change engine behavior: g (global) finds all matches, i (case insensitive), m (multiline) makes ^ and $ match line boundaries, s (dotall) makes . match newlines. Choose flags based on your use case.
Common pitfalls include greedy quantifiers matching too much (use *? for lazy), catastrophic backtracking from nested quantifiers like (a+)+, and engine differences across languages. Always test incrementally and consider adversarial inputs.