Regex Cheatsheet & Tester

IT

Complete guide to regular expressions with interactive tester. Test your patterns in real-time and use ready-to-use common patterns.

Regex Tester

/ /

Results

0 matches
Results will appear here...

Common Patterns (click to use)

Email
Standard email validation
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
URL
HTTP/HTTPS URL
^https?:\/\/[\w\-]+(\.[\w\-]+)+[\/\w\-._~:?#\[\]@!$&'()*+,;=]*$
US Phone
US phone number
^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$
UK Phone
UK phone number
^(\+44|0)[0-9]{10,11}$
IPv4
IPv4 address
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
IPv6
IPv6 address (simplified)
^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$
MAC Address
MAC address
^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$
Date US
Date MM/DD/YYYY
^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/\d{4}$
Date ISO
Date YYYY-MM-DD
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
Time
Time HH:MM or HH:MM:SS
^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$
Strong Password
Min 8 chars, upper, lower, number, special
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
Username
Username 3-16 chars, starts with letter
^[a-zA-Z][a-zA-Z0-9_]{2,15}$
Hashtag
Social hashtag
#[a-zA-Z0-9_]+
Mention
Social mention (@username)
@[a-zA-Z0-9_]+
Credit Card
Credit card number (digits only)
^[0-9]{13,19}$
SSN
US Social Security Number
^\d{3}-\d{2}-\d{4}$
ZIP Code US
US ZIP code
^\d{5}(-\d{4})?$
UK Postcode
UK postal code
^[A-Z]{1,2}[0-9][A-Z0-9]? ?[0-9][A-Z]{2}$
URL Slug
SEO-friendly URL slug
^[a-z0-9]+(?:-[a-z0-9]+)*$
Hex Color
Hexadecimal color
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$

Complete Cheatsheet

Basic Characters

Pattern Description Example Matches
. Any character (except newline) a.c abc, a1c, a-c
\d Digit (0-9) \d{3} 123, 456
\D Non-digit \D+ abc, xyz
\w Word character (a-z, A-Z, 0-9, _) \w+ hello_123
\W Non-word character \W !, @, #
\s Whitespace (space, tab, newline) \s+ , \t
\S Non-whitespace \S+ abc123
\\ Literal backslash C:\\ C:\

Anchors (Position)

Pattern Description Example Matches
^ Start of string/line ^Hello Hello world (start)
$ End of string/line world$ Hello world (end)
\b Word boundary \bword\b word (whole word)
\B Non-word boundary \Bword sword (inside)
\A Absolute start of string \AStart Start (only start)
\Z Absolute end of string end\Z end (only end)

Quantifiers

Pattern Description Example Matches
* Zero or more (greedy) a* , a, aa, aaa
+ One or more (greedy) a+ a, aa, aaa
? Zero or one (optional) colou?r color, colour
{n} Exactly n times \d{4} 2024 (4 digits)
{n,} n or more times \d{2,} 12, 123, 1234
{n,m} From n to m times \d{2,4} 12, 123, 1234
*? Zero or more (lazy/non-greedy) a*? minimal match
+? One or more (lazy) a+? minimal match
?? Zero or one (lazy) a?? minimal match

Groups and References

Pattern Description Example Matches
(abc) Capturing group (\d+)-(\d+) 123-456 (captures both)
(?:abc) Non-capturing group (?:ab)+ ab, abab (no capture)
(?<name>) Named group (?<year>\d{4}) 2024 (name: year)
\1, \2 Backreference (\w)\1 aa, bb (double chars)
(?=abc) Positive lookahead foo(?=bar) foo if followed by bar
(?!abc) Negative lookahead foo(?!bar) foo if NOT followed by bar
(?<=abc) Positive lookbehind (?<=@)\w+ word after @
(?<!abc) Negative lookbehind (?<!@)\w+ word NOT after @

Character Classes

Pattern Description Example Matches
[abc] One of a, b, c [aeiou] vowels
[^abc] None of a, b, c [^0-9] non-digits
[a-z] Range from a to z [a-zA-Z] letters
[0-9] Range from 0 to 9 [0-9]+ numbers
[a-zA-Z0-9] Alphanumeric [a-zA-Z0-9_]+ identifiers

Alternation and Escape

Pattern Description Example Matches
| OR (alternation) cat|dog cat or dog
\ Escape special characters \$100 $100 (literal)
[] Special chars in class [\[\]] [ or ]

Flags/Modifiers

Pattern Description Example Matches
i Case insensitive /hello/i hello, HELLO, Hello
g Global (all occurrences) /a/g all "a"s
m Multiline (^ and $ for each line) /^line/m start of each line
s Dotall (. includes newline) /a.b/s a\nb
u Unicode /\p{L}/u Unicode letters