Quick reference guide for common regular expressions with examples.
. 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
* 0 or more
+ 1 or more
? 0 or 1 (optional)
{3} Exactly 3
{2,5} Between 2 and 5
{2,} 2 or more
(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
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}$/
g Global โ find all matches i Case insensitive m Multiline (^ and $ match line start/end) s Dotall (. matches newline too)
Result will appear here...
Regular expressions are patterns used to match character combinations in strings. They are widely used for validation, parsing and search operations.