Regex Tester & Reference FAQ

Highlighted Matches



    

Match & Capture Groups



            

Regex FAQ & Cheat Sheet

Groups & Backreferences

SyntaxMeaningExample
(abc)Capturing group #1(foo|bar) matches foo or bar
(?:abc)Non-capturing group (groups without storing)(?:https?:\/\/)?example\.com
(?<name>abc)Named capturing group(?<year>\d{4})
\1, \k<name>Backreference to matched group(\w+)\s+\1 matches repeated words

Lookahead & Lookbehind (Zero-Width Assertions)

SyntaxNameExample
(?=abc)Positive lookahead\d+(?=px) matches 12 in 12px
(?!abc)Negative lookaheadfoo(?!bar) matches foo not followed by bar
(?<=abc)Positive lookbehind(?<=\$)\d+ matches 100 in $100
(?<!abc)Negative lookbehind(?<!-)\b\d+ matches positive numbers only

Common Anchors, Classes & Quantifiers

TokenDescription
^ / $Start / end of string (or line with m flag)
\b / \BWord boundary / non-word boundary
\d, \w, \sDigit, word char ([A-Za-z0-9_]), whitespace
*, +, ?, {n,m}0+, 1+, 0 or 1, between n and m times (append ? for lazy, e.g. .*?)

Understanding Regex Flags

JavaScript regular expressions accept single-letter flags after the closing delimiter that change how the engine scans your test string:

  • g (Global): Finds all matches in the input instead of stopping after the first match. Required when highlighting every occurrence in a log or extracting multiple tokens.
  • i (Case-Insensitive): Treats uppercase and lowercase ASCII/Unicode letters as equivalent (/error/i matches Error, ERROR, and error).
  • m (Multiline): Changes ^ and $ so they match the start and end of each individual line rather than only the start and end of the entire string.
  • s (DotAll): Allows the dot . metacharacter to match newline characters (\n), which is essential when matching multi-line blocks.

Common Pitfalls, Performance & FAQ

  • Greedy vs. Lazy Quantifiers: By default, * and + are greedy - <.*> on <b>hi</b> matches the entire string from the first < to the last >. Adding ? (<.*?>) makes the quantifier lazy so it stops at the nearest closing bracket.
  • What is catastrophic backtracking (ReDoS)? Nested quantifiers like (a+)+ can cause exponential evaluation time on non-matching inputs. Keep character classes specific (use [^"]+ instead of .* inside quotes) and avoid overlapping repetition inside groups.
  • When should I use non-capturing groups (?:...)? Whenever you only need parentheses for grouping alternation like (?:http|https):// without cluttering your numbered capture groups ($1, $2) or allocating extra match arrays.
  • How do lookarounds work without consuming characters? Lookaheads ((?=...), (?!...)) and lookbehinds ((?<=...), (?<!...)) assert that a pattern exists immediately after or before the current cursor position without including those characters in the final matched text.
  • Is my test data sent to any server? No. All pattern compilation, match highlighting, and capture-group extraction run locally in your browser's JavaScript RegExp engine.
Please read the privacy policy (agreement of the cookies usage, other websites embedded content, etc.). If you continue to use the site, we will assume that you agree with our privacy policy.
OkPrivacy Policy