Developer
Regex for beginners: the only 10 patterns you need
Match emails, phone numbers, dates, URLs, and 6 more common patterns — with explanations you’ll remember.
The core syntax
.any character*0 or more+1 or more?optional\ddigit,\wword char,\swhitespace[abc]character class^start,$end(...)capture group
10 most-used patterns
- Email:
[\w.-]+@[\w.-]+\.\w+ - Phone (Indian):
(?:\+91|0)?[6-9]\d{9} - Date YYYY-MM-DD:
\d{4}-\d{2}-\d{2} - URL:
https?://[^\s]+ - PAN:
[A-Z]{5}\d{4}[A-Z] - GSTIN:
\d{2}[A-Z]{5}\d{4}[A-Z][A-Z\d]Z[A-Z\d] - IPv4:
\d{1,3}(?:\.\d{1,3}){3} - Hex color:
#[0-9a-fA-F]{6} - Whitespace cleanup:
\s+ - Trim:
^\s+|\s+$
Use Elevatools Regex Generator to convert plain English to regex instantly.
Related reads