Common Regex Patterns
Ready-to-use patterns for everyday tasks. Click "Try it" to open in the regex tester with sample data.
Common
Email Address
Matches most common email address formats.
/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/gURL
Matches HTTP and HTTPS URLs.
/https?://[\w.-]+(?:\.[a-z]{2,})(?:/[\w./?%&=-]*)?/giPhone Number (US)
Matches US phone numbers in various formats.
/(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/gUUID
Matches UUID/GUID format.
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/giFile Extension
Extracts file extension from a filename.
/\.(\w+)$/gmNetworking
IPv4 Address
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
Web
Hex Color
Matches 3 or 6 digit hex color codes.
/#(?:[0-9a-fA-F]{3}){1,2}\b/gHTML Tag
Matches paired HTML tags with content.
/<([a-z][a-z0-9]*)\b[^>]*>.*?</\1>/giMarkdown Link
Matches Markdown-style links [text](url).
/\[([^\]]+)\]\(([^)]+)\)/gCSS Property
Matches CSS property-value pairs.
/([a-z-]+)\s*:\s*([^;]+);/gValidation
Password Strength
Requires lowercase, uppercase, digit, special char, min 8 chars.
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/gmText Processing
Whitespace Trimming
Matches leading and trailing whitespace.
/^\s+|\s+$/gmDuplicate Words
Finds consecutive duplicate words.
/\b(\w+)\s+\1\b/giQuoted String
Matches single or double quoted strings with escape support.
/(["'])(?:(?!\1|\\).|\\.)*\1/gCamel to Snake Case
Matches camelCase boundaries. Replace with $1_$2 and lowercase.
/([a-z])([A-Z])/gNumbers
Code
Import Statement
Matches JavaScript/TypeScript import statements.
/import\s+(?:\{[^}]+\}|\w+)\s+from\s+['"]([^'"]+)['"]/g