JavaScript Regex Tutorial

Interactive Regex Tutorial

Matches:

Regex Cheat Sheet

Character Classes

  • . - Any character except newline
  • \w - Word character (a-z, A-Z, 0-9, _)
  • \d - Digit (0-9)
  • \s - Whitespace character
  • [abc] - Any of a, b, or c
  • [^abc] - Any character except a, b, or c

Quantifiers

  • * - 0 or more
  • + - 1 or more
  • ? - 0 or 1
  • {n} - Exactly n times
  • {n,} - n or more times
  • {n,m} - Between n and m times

Anchors

  • ^ - Start of string
  • $ - End of string
  • \b - Word boundary

Groups and Lookaround

  • (abc) - Capture group
  • (?:abc) - Non-capturing group
  • (?=abc) - Positive lookahead
  • (?!abc) - Negative lookahead

Learn More

Regular expressions are a powerful tool for pattern matching and text manipulation. To dive deeper into regex, check out these resources:

A comic about Regular Expressions