RegEx Cheat Sheet & Live Match Visualizer
Test and debug JavaScript regular expressions in real time. Inspect match ranges, analyze numbered capture groups, toggle global/multiline flags, and quickly reference syntax tokens from the interactive cheat sheet.
1. Regular Expression Pattern
ECMAScript Regex2. Test String Target
3. Capture Groups & Match Table
3 matches identifiedComplete Guide to Regular Expression Matching & Optimization
Regular expressions (regex) provide declarative syntax for pattern matching, validation, extraction, and lexical tokenization across virtually all modern programming languages. Built on deterministic finite automata (DFA) and non-deterministic finite automata (NFA) engines, regular expressions process string streams by comparing character classes, repetition quantifiers, and boundary assertions.
1. Greedy vs. Lazy Quantifiers
Standard quantifiers (*, +, {n,}) are greedy: they match as much text as possible before backtracking. Adding a question mark (*?, +?) converts them to lazy, matching the minimum number of characters required.
2. Capture Groups & Backreferences
Parentheses (...) capture matching sub-expressions into numbered variables ($1, $2) for string replacement. Non-capturing groups (?:...) group tokens for quantification without allocating memory overhead for match variables.
3. Lookahead & Lookbehind
Zero-width assertions verify that preceding or following text matches a condition without consuming characters in the match result. Positive lookahead (?=...) and negative lookahead (?!...) enable password strength and boundary filtering.
Frequently Asked Questions
What is the difference between the 'g' and 'm' flags?
The global (g) flag instructs the engine to find all matches across the input string rather than stopping after the first occurrence. The multiline (m) flag changes the behavior of ^ and $ anchors so they match the start and end of every individual line rather than the entire input string.
How can I prevent Catastrophic Backtracking (ReDoS)?
Catastrophic backtracking occurs when nested quantifiers (e.g. (a+)+$) create exponential branch permutations on non-matching strings. To prevent ReDoS, avoid overlapping character classes within quantified groups and employ atomic grouping or possessive quantifiers where supported.
Related Developer & Web Tools Calculators
Cron Expression Explainer & Visual Schedule Generator
Free interactive Cron Expression Explainer & Visual Schedule Generator with instant calculations, visual breakdown, formula explanation, and export options.
JSON to TypeScript Interface / Zod Schema Generator
Free interactive JSON to TypeScript Interface / Zod Schema Generator with instant calculations, visual breakdown, formula explanation, and export options.
CSS Box Shadow & Glassmorphism Code Generator
Free interactive CSS Box Shadow & Glassmorphism Code Generator with instant calculations, visual breakdown, formula explanation, and export options.
PX to REM Responsive Converter with Live Table
Free interactive PX to REM Responsive Converter with Live Table with instant calculations, visual breakdown, formula explanation, and export options.
Concrete Slab Yardage Calculator
Free interactive Concrete Slab Yardage Calculator with instant calculations, visual breakdown, formula explanation, and export options.
TikTok Creator Rewards Fund Calculator
Free interactive TikTok Creator Rewards Fund Calculator with instant calculations, visual breakdown, formula explanation, and export options.
Texas Paycheck Calculator Hourly
Free interactive Texas Paycheck Calculator Hourly with instant calculations, visual breakdown, formula explanation, and export options.
Golf Handicap Index & Course Handicap Calculator
Free interactive Golf Handicap Index & Course Handicap Calculator with instant calculations, visual breakdown, formula explanation, and export options.