Regex Recipes
Ready-to-use regular expression patterns for common validation and extraction tasks
Email Validation (Strict)
Practical strict email validation pattern that balances real-world usage with RFC compliance.
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$URL Validation (HTTP/HTTPS)
Validate HTTP and HTTPS URLs including query strings and fragments.
^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)$Hex Color Code
Match hexadecimal color codes in both 3-digit and 6-digit formats.
^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$UUID v4 Validation
Validate UUID version 4 format with strict formatting.
^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$URL Slug Validation
Validate URL-friendly slugs with lowercase letters, numbers, and hyphens.
^[a-z0-9]+(?:-[a-z0-9]+)*$ISO Date Format (YYYY-MM-DD)
Validate ISO 8601 date format (YYYY-MM-DD). Note: validates format only, not actual date validity.
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$Email Validation (Permissive)
Very permissive email pattern for loose input acceptance. Use when you want to avoid false rejections.
^.+@.+\..+$Domain Name Validation
Validate domain names with support for subdomains and international domains (with punycode note).
^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$IPv4 Address Validation
Strict IPv4 address validation ensuring each octet is 0-255.
^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$IPv6 Address (Basic)
Basic IPv6 address validation with common format support and important caveats.
^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:)$Port Number (1-65535)
Validate network port numbers in valid range 1-65535.
^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$Username (Safe)
Safe username validation with letters, numbers, dots, underscores, and hyphens with length rules.
^[a-zA-Z0-9._-]{3,20}$Strong Password Baseline
Password strength validation requiring minimum length and character class diversity with UX notes.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$Time Format (HH:MM 24-hour)
Validate 24-hour time format (HH:MM) with proper hour (00-23) and minute (00-59) validation.
^([01]?[0-9]|2[0-3]):[0-5][0-9]$Extract Text Between Quotes
Extract content between double quotes with greedy vs lazy matching examples.
"([^"]*)"Extract Content Inside Parentheses
Extract text inside parentheses with nested limitation notes.
\(([^)]*)\)Remove Duplicate Spaces
Find and replace multiple consecutive spaces with a single space.
{2,}Trim Leading/Trailing Whitespace
Remove whitespace from start and end of lines with multiline variations.
^\s+|\s+$Find Trailing Spaces
Detect trailing whitespace at end of lines for code cleanup.
+$Detect Repeated Words
Find accidentally repeated words like "the the" in text.
\b(\w+)\s+\1\bFind TODO/FIXME Comments
Scan code for TODO, FIXME, HACK, and NOTE comments.
(TODO|FIXME|HACK|NOTE|XXX):?\s*(.*)$Credit Card Format (Luhn Disclaimer)
Match credit card number formats. WARNING: Format match only - must run Luhn algorithm separately for validation.
^\d{13,19}$Phone Number (E.164 International)
Validate international phone numbers in E.164 format (+country code without spaces).
^\+[1-9]\d{1,14}$Serbian Phone Numbers
Validate Serbian phone numbers with local format patterns.
^(\+381|0)[1-9]\d{7,8}$ZIP/Postal Code (Generic)
Generic postal code validation with country-specific notes.
^[A-Z0-9]{3,10}$HTML Tag Stripper (WARNING)
Basic HTML tag removal pattern. WARNING: Regex cannot reliably parse HTML - use proper HTML parser.
<[^>]+>Markdown Heading Detection
Detect markdown headings with ATX-style # syntax.
^#{1,6}\s+.+$Extract Hashtags
Extract social media hashtags with Unicode support for international characters.
#[\w\u00C0-\u017F]+Extract @Mentions
Extract social media @mentions and @usernames from text.
@[\w]{1,15}Semantic Version (x.y.z)
Validate semantic versioning with optional prerelease and build metadata.
^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$File Extension Whitelist
Validate file extensions against a whitelist of allowed types.
\.(jpg|jpeg|png|gif|webp)$Windows Path (Basic)
Match Windows file paths with drive letter and backslashes. Includes escaping examples.
^[A-Za-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$Unix Path (Basic)
Match Unix/Linux file paths for both absolute and relative paths.
^(/)?([^/\0]+(/)?)+$Base64 Detection
Detect Base64-encoded strings with padding variation support.
^[A-Za-z0-9+/]+={0,2}$Detect Non-ASCII Characters
Find characters outside ASCII range (0-127) for text sanitization.
[^\x00-\x7F]