SpeedDrain
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)
Contact us at [email protected] or [email protected] today.

Capture Group Details

#Full MatchIndexGroups ($1, $2, ...)Named Groups
1[email protected]14NoneNone
2[email protected]41NoneNone

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) matches 24 in 24px without including px.
  • Negative Lookahead (?!...): Asserts that what follows does NOT match. Example: \d+(?!px) matches numbers not followed by px.
  • 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 like aaaaaaaaaaaaaaaaaaaaX.
  • 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.