Regex Tester
Test your regex pattern
/
Regex Common Patterns
Whole Numbers/^\d+$/gm
Decimal Numbers/^\d*\.\d+$/gm
Alphanumeric without spaces/^[a-zA-Z0-9]+$/gm
Alphanumeric with spaces/^[a-zA-Z0-9 ]+$/gm
Email Address/^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/gm
Password (8 char, 1 upper, 1 lower, 1 number, 1 special)/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/gm
Username/^[a-zA-Z0-9_-]{3,16}$/gm
URL/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\([-a-zA-Z0-9@:%_\+.~#()?&//=]*)/gm
IPv4 Address/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm
Date (YYYY-MM-DD)/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/gm
Date (dd-MM-yyyy using separators - / .)/^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/gm
Date (dd-mmm-YYYY using separators - / .)/^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]|(?:Jan|Mar|May|Jul|Aug|Oct|Dec)))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2]|(?:Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)(?:0?2|(?:Feb))\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9]|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep))|(?:1[0-2]|(?:Oct|Nov|Dec)))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/gm
Time (HH:MM 12-hour format)/^(0?[1-9]|1[0-2]):[0-5][0-9]$/gm
Time (HH:MM 12-hour format with AM/PM)/((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))/gm
Time (HH:MM 24-hour format)/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/gm
Time (HH:MM 24-hour format optional leading zero)/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/gm
Time (HH:MM:SS 24-hour format)/(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)/gm
HTML Tag/<\/?[\w\s]*>|<.+[\W]>/gm
Inline JS/\on\w+=\S+(?=.*>)/gm
Inline JS with element/(?:<[^>]+\s)(on\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/gm
Hex Color/#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/gm
Slug/^[a-z0-9]+(?:-[a-z0-9]+)*$/gm
Phone Number with country code/\+?[0-9]{1,3}-?[0-9]{3}-?[0-9]{3}-?[0-9]{4}/gm
Credit Card Number/\(?:\d[ -]*?){13,16}\/gm
Regex Cheatsheet
A quick reference for regex syntax
Character classes
.
any character except newline\w\d\s
word, digit, whitespace[abc]
any of a, b, or c[^abc]
not a, b, or c[a-g]
character between a & gAnchors
^abc$
start / end of the string\b\B
word, not-word boundaryEscaped characters
\.\*\\
escaped special characters\t\n\r
tab, linefeed, carriage returnGroups & Lookaround
(abc)
capture group\1
backreference to group #1(?:abc)
non-capturing group(?=abc)
positive lookahead(?!abc)
negative lookaheadQuantifiers & Alternation
a*a+a?
0 or more, 1 or more, 0 or 1a{5}a{2,}
exactly five, two or morea{1,3}
between one & threea+?a{2,}?
match as few as possibleab|cd
match ab or cd