Regular expressions are one of the most powerful tools in a developer's toolkit — and one of the most frustrating to write from scratch. You know the pattern exists, you've written it before, and yet every time you need to validate an email address or extract a URL, you end up on Stack Overflow searching for the same regex.
This cheat sheet is designed to end that cycle. Patterns below are starting points to test against your own valid and invalid examples. Use our Regex Tester to try any pattern with your own test strings.
Email Address Validation
Basic pattern:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$This matches standard email formats like user@domain.com, first.last@company.co.uk, and user+tag@gmail.com.
What it checks: One or more alphanumeric characters (plus dots, underscores, percent, plus, hyphen) before the @, followed by a domain name with at least one dot and a TLD of 2+ characters.
Edge cases it handles: Subdomains (user@mail.company.com), plus-addressing (user+tag@gmail.com), hyphens in domains.
What it doesn't handle: Quoted local parts ("user name"@domain.com), IP address domains (user@[192.168.1.1]), and some valid but uncommon formats. For 99% of form validation, this pattern is sufficient.
URL Validation
Pattern (HTTP/HTTPS):
^https?:\/\/([\w-]+\.)+[\w-]+(\/[\w\-./?%&=]*)?$Matches URLs like https://example.com, http://sub.domain.co.uk/path?key=value, and https://api.example.com/v2/users.
Phone Number Patterns
International format (E.164):
^\+[1-9]\d{1,14}$Matches: +14155552671, +919876543210, +442071234567
Indian mobile number:
^(?:\+91|91|0)?[6-9]\d{9}$Matches: +919876543210, 09876543210, 9876543210, 6123456789
US phone number:
^(?:\+1)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$Matches: (555) 123-4567, 555-123-4567, +15551234567, 555.123.4567
Password Strength Validation
Pattern (minimum 8 chars, uppercase, lowercase, digit, special char):
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$This uses lookaheads to assert the presence of each required character type without enforcing a specific order. Test your regex against sample passwords using our Regex Tester.
Date Format Patterns
DD/MM/YYYY:
^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/\d{4}$YYYY-MM-DD (ISO 8601):
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$Note: These validate format only — they don't catch invalid dates like 31/02/2026. For full date validation, parse with your language's date library after regex matching.
IP Address Patterns
IPv4:
^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$Matches valid IPv4 addresses (0.0.0.0 to 255.255.255.255) and rejects invalid octets like 256.1.1.1.
HTML Tag Extraction
Match opening HTML tags:
<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>Match content between specific tags:
<title>(.*?)<\/title>Important caveat: Regex should not be used to parse complex or nested HTML. Use a proper HTML parser (DOMParser, BeautifulSoup, Cheerio) for anything beyond simple tag extraction. Regex is fine for quick searches in known, simple HTML structures.
Common Text Patterns
Remove all HTML tags:
<[^>]*>Match whitespace-only lines:
^\s*$Extract numbers from text:
\d+\.?\d*Match hex color codes:
#(?:[0-9a-fA-F]{3}){1,2}\bTry all of these patterns with real text in our Regex Tester — it lists matching text and shows a preview; it does not provide a separate capture-group inspector.
Regex Flags Quick Reference
| Flag | Name | Effect |
|---|---|---|
| g | Global | Find all matches, not just the first |
| i | Case-insensitive | A matches both 'a' and 'A' |
| m | Multiline | ^ and $ match start/end of each line, not just the string |
| s | Dotall | . matches newline characters too |
| u | Unicode | Enables Unicode-aware matching |