cordky

Regex Tester & Pattern Explainer

Test JavaScript regular expressions with live highlighting, detailed explanations, and common pattern library.

Regular Expression Pattern

Flags:

Test Text

93 chars

No matches found

Regex Learning Resources
Master regular expressions with comprehensive examples and best practices

Basic Syntax:

  • . - Matches any character except newline
  • * - Zero or more of previous (greedy)
  • + - One or more of previous (greedy)
  • ? - Zero or one of previous (optional)
  • ^ - Start of string/line anchor
  • $ - End of string/line anchor
  • \ - Escape special characters

Character Classes:

  • \d - Digit [0-9]
  • \w - Word character [a-zA-Z0-9_]
  • \s - Whitespace character
  • \D - Non-digit character
  • \W - Non-word character
  • \S - Non-whitespace character
  • [abc] - Any of a, b, or c
  • [a-z] - Range a to z
  • [^abc] - Not a, b, or c

Advanced Features:

  • () - Capturing group
  • (?:) - Non-capturing group
  • | - Alternation (OR)
  • {n,m} - Quantity n to m times
  • (?=) - Positive lookahead
  • (?!) - Negative lookahead
  • *? - Non-greedy (lazy) matching
  • \b - Word boundary

Common Use Cases:

Extract Numbers:

\d+

Matches one or more digits

Remove Extra Spaces:

\s+

Matches one or more whitespace characters

Word Boundaries:

\bword\b

Matches "word" as a complete word only

Performance Tips:

✓ Use specific patterns

Prefer \d+ over .+ for numbers

✓ Anchor when possible

Use ^ and $ to avoid backtracking

✗ Avoid nested quantifiers

Patterns like (a+)+ can cause exponential time

✗ Multiple .* patterns

Can cause catastrophic backtracking

JavaScript Regex Flags:

g - Global: Find all matches
i - Ignore case: Case-insensitive
m - Multiline: ^ and $ match line breaks
s - Dot all: . matches newline
u - Unicode: Full Unicode support
y - Sticky: Match only at lastIndex