Common Regex Patterns
Ready-to-use patterns for everyday tasks. Open any name for its railroad diagram, a plain-English breakdown and worked test cases, or hit "Try it" to load it straight into the regex tester with sample data.
Common
Matches most common email address formats.
/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/gMatches HTTP and HTTPS URLs.
/https?://[\w.-]+(?:\.[a-z]{2,})(?:/[\w./?%&=-]*)?/giMatches US phone numbers in various formats.
/(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/gMatches UUID/GUID format.
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/giExtracts file extension from a filename.
/\.(\w+)$/gmNetworking
Matches valid IPv4 addresses (0.0.0.0 to 255.255.255.255).
/\b(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/gDates & Times
Matches dates in ISO 8601 format.
/\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/gMatches 24-hour time format.
/(?:[01]\d|2[0-3]):[0-5]\d/gWeb
Matches 3 or 6 digit hex color codes.
/#(?:[0-9a-fA-F]{3}){1,2}\b/gMatches paired HTML tags with content.
/<([a-z][a-z0-9]*)\b[^>]*>.*?</\1>/giMatches Markdown-style links [text](url).
/\[([^\]]+)\]\(([^)]+)\)/gMatches CSS property-value pairs.
/([a-z-]+)\s*:\s*([^;]+);/gValidation
Requires lowercase, uppercase, digit, special char, min 8 chars.
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/gmText Processing
Matches leading and trailing whitespace.
/^\s+|\s+$/gmFinds consecutive duplicate words.
/\b(\w+)\s+\1\b/giMatches single or double quoted strings with escape support.
/(["'])(?:(?!\1|\\).|\\.)*\1/gMatches camelCase boundaries. Replace with $1_$2 and lowercase.
/([a-z])([A-Z])/gNumbers
Matches positive integers (no leading zeros, no negatives).
/(?<![-\d])[1-9]\d*\b/gMatches decimal numbers including negative.
/-?\d+\.\d+/gCode
Matches JavaScript/TypeScript import statements.
/import\s+(?:\{[^}]+\}|\w+)\s+from\s+['"]([^'"]+)['"]/g