Regex Generator
Build regex patterns from named blocks or pick a ready-made template. Then test it in the tester.
How to use this generator
π Using Templates
- Browse or search the template library
- Click Show examples to preview what it matches
- Click Use to load it into the pattern input
- Adjust flags (g, i, mβ¦) as needed
- Click Test & Visualize β to test it
π§ Using Block Builder
- Switch to the Block Builder tab
- Click any block to append it to your pattern
- Active blocks appear as chips above - click Γ to remove one
- Edit the raw pattern manually anytime
- Mix and match blocks to compose complex patterns
π© Flags explained
gGlobal - find all matches, not just the firstiCase-insensitive matchingmMultiline - ^ and $ match line starts/endssDotall - . also matches newlinesuUnicode - enables full Unicode support
β Warnings explained
- Nested quantifiers - patterns like (a+)+ can freeze your app on long non-matching strings. Refactor to be more specific.
- Greedy .* hint - .* matches everything first then backtracks. Use .*? when you want the shortest match.
- Anchor hint - without ^ and $, a validation pattern can match inside a larger string.
Your regex appears here as you build it
Email (strict)
Validate email addresses
/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/iURL
Match HTTP/HTTPS URLs
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/giIPv4 address
Valid IPv4 addresses
/\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/gIPv6 address
Full IPv6 addresses
/([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}/gISO date (YYYY-MM-DD)
ISO 8601 date format
/\b\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\b/gTime (24-hour)
24-hour time HH:MM or HH:MM:SS
/\b([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?\b/gTime (12-hour)
12-hour time with AM/PM
/\b(1[0-2]|0?[1-9]):([0-5]\d)(?::([0-5]\d))? ?(AM|PM|am|pm)\b/gInternational phone
E.164 international phone format
/\+?[1-9]\d{1,14}/gHex color
CSS hex color codes
/#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/giCredit card number
16-digit card numbers
/\b(?:\d{4}[\s\-]?){3}\d{4}\b/gUUID v4
UUID v4 format
/\b[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/giUS ZIP code
5 or 9 digit US ZIP
/\b\d{5}(?:-\d{4})?\b/gStrong password
8+ chars with upper, lower, digit, special
/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}/URL slug
Lowercase hyphenated slug
/^[a-z0-9]+(?:-[a-z0-9]+)*$/Username
3-20 chars, starts with letter
/^[a-zA-Z][a-zA-Z0-9_-]{2,19}$/Extract emails
Find all email addresses in text
/[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}/gExtract URLs
Find all URLs in text
/https?:\/\/[^\s<>"{}|\\^`\[\]]+/gExtract IP addresses
Find all IP-like strings
/\b(?:\d{1,3}\.){3}\d{1,3}\b/gExtract dates
Find date-like patterns
/\b\d{1,4}[-/.]\d{1,2}[-/.]\d{1,4}\b/gExtract prices
Find currency amounts
/[$Β£β¬Β₯]\s?\d+(?:[.,]\d{1,2})?(?:\s?[KkMmBb])?/gHashtags
Find hashtags
/#[a-zA-Z][\w]{0,29}/gMentions (@user)
Find @mentions
/@[a-zA-Z][\w]{0,29}/gAll numbers
Find all numbers (int or float)
/-?\d+(?:\.\d+)?/gTrim whitespace
Match leading and trailing whitespace
/^\s+|\s+$/gMultiple spaces
Match 2+ consecutive spaces
/\s{2,}/gHTML tags
Match HTML tags for stripping
/<[^>]+>/gcamelCase splitter
Split at camelCase boundaries
/(?<=[a-z])(?=[A-Z])/gBlank lines
Match empty or whitespace-only lines
/^\s*$/gmJS line comments
Match // line comments
/\/\/.*$/gm