50+ Regex Tokens · Live Match Highlighting · Group Extraction
Regex Cheatsheet & Tester Builder
Build, inspect, and master regular expressions. Browse syntax categories, test against sample data in real-time, and extract numbered or named capture groups with zero latency.
Presets:
/gu
65 chars
Live Matches Highlight (2)
Capture Group Details
| # | Full Match | Index | Groups ($1, $2, ...) | Named Groups |
|---|---|---|---|---|
| 1 | [email protected] | 14 | None | None |
| 2 | [email protected] | 41 | None | None |
Regex Cheatsheet Catalog (Click to Insert)
Regular Expression Mastery: Lookaround Assertions, Greedy Engines & ReDoS
Zero-Width Lookaround Assertions
Lookaround expressions match positions without consuming characters from the text stream:
- Positive Lookahead
(?=...): Asserts that what follows matches the sub-pattern. Example:\d+(?=px)matches24in24pxwithout includingpx. - Negative Lookahead
(?!...): Asserts that what follows does NOT match. Example:\d+(?!px)matches numbers not followed bypx. - Lookbehind
(?<=...)and(?<!...): Examines characters immediately preceding the match target (e.g.(?<=\$)\d+to match dollar amounts without the symbol).
Avoiding Catastrophic Backtracking (ReDoS)
Standard NFA (Nondeterministic Finite Automaton) regex engines evaluate nested quantifiers via recursive backtracking:
- The Dangerous Pattern: Patterns like
(a+)+$or([a-zA-Z0-9]+)*$have exponential $O(2^n)$ worst-case time complexity when evaluated against non-matching strings likeaaaaaaaaaaaaaaaaaaaaX. - The Fix: Use possessive quantifiers, atomic groups, or rewrite overlapping tokens to make branches mutually exclusive.
Greedy vs. Lazy Quantifiers
By default, quantifiers like * and + are greedy—they consume as much text as possible. In an HTML string like <b>bold</b>, the pattern <.*> matches the entire string. Adding a question mark <.*?> converts the quantifier to lazy (or reluctant), matching only the first closing tag.