Regex Basics
Regular expressions are powerful pattern-matching tools used in every programming language. Here's a quick reference for the patterns you'll use most often.
Character Classes
.— Any character except newline\d— Any digit (0-9)\w— Any word character (a-z, A-Z, 0-9, _)\s— Any whitespace (space, tab, newline)[abc]— Any of a, b, or c[^abc]— Not a, b, or c[a-z]— Any lowercase letter
Quantifiers
*— 0 or more+— 1 or more?— 0 or 1{3}— Exactly 3{3,}— 3 or more{3,5}— Between 3 and 5
Common Patterns
- Email:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ - URL:
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*) - IPv4:
^((25[0-5]|(2[0-4]|1?\d)?\d)\.){3}(25[0-5]|(2[0-4]|1?\d)?\d)$ - Date (YYYY-MM-DD):
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ - Phone (US):
^\+?1?[-.]?\(?\d{3}\)?[-.]?\d{3}[-.]?\d{4}$ - Hex Color:
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
Anchors & Groups
^— Start of string$— End of string(abc)— Capture group(?:abc)— Non-capture group(?=abc)— Positive lookahead(?!abc)— Negative lookahead
Test Your Patterns
Don't just guess — test your regex patterns with real input. Our Regex Tester shows matches in real-time with group highlighting and error explanations.