Regex Cheatsheet

Quick reference guide for common regular expressions with examples.

Common Patterns

.        Any character (except newline)
\d       Digit (0-9)
\D       Non-digit
\w       Word character (a-z, A-Z, 0-9, _)
\W       Non-word character
\s       Whitespace (space, tab, newline)
\S       Non-whitespace
\b       Word boundary
^        Start of string
$        End of string

Quantifiers

*        0 or more
+        1 or more
?        0 or 1 (optional)
{3}      Exactly 3
{2,5}    Between 2 and 5
{2,}     2 or more

Groups & Lookaround

(abc)       Capture group
(?:abc)     Non-capturing group
a|b         Alternation (a or b)
(?=abc)     Positive lookahead
(?!abc)     Negative lookahead
(?<=abc)    Positive lookbehind
(?<!abc)    Negative lookbehind

Useful Examples

Email:        /^[^\s@]+@[^\s@]+\.[^\s@]+$/
URL:          /^https?:\/\/.+/
Numbers:      /^\d+$/
Username:     /^[a-zA-Z0-9_]{3,16}$/
Hex color:    /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
IPv4:         /^(\d{1,3}\.){3}\d{1,3}$/
Date:         /^\d{4}-\d{2}-\d{2}$/

Flags

g   Global โ€” find all matches
i   Case insensitive
m   Multiline (^ and $ match line start/end)
s   Dotall (. matches newline too)

Test Regex

Result will appear here...

How to use this cheatsheet

  1. Browse the tables to find the regex syntax you need
  2. Check the examples column for practical usage patterns
  3. Use the inline tester to experiment with patterns on live text
  4. Combine patterns from different sections to build complex expressions

What is Regex?

Regular expressions are patterns used to match character combinations in strings. They are widely used for validation, parsing and search operations.

Related tools

๐Ÿงช Regex Tester ๐Ÿ“ง Email Regex Generator ๐Ÿ” Regex Replace