βš™
useprecisoDevTools

Regex Generator

Build regex patterns from named blocks or pick a ready-made template. Then test it in the tester.

//
Flags:
How to use this generator

πŸ“š Using Templates

  1. Browse or search the template library
  2. Click Show examples to preview what it matches
  3. Click Use to load it into the pattern input
  4. Adjust flags (g, i, m…) as needed
  5. Click Test & Visualize β†’ to test it

πŸ”§ Using Block Builder

  1. Switch to the Block Builder tab
  2. Click any block to append it to your pattern
  3. Active blocks appear as chips above - click Γ— to remove one
  4. Edit the raw pattern manually anytime
  5. Mix and match blocks to compose complex patterns

🚩 Flags explained

  • gGlobal - find all matches, not just the first
  • iCase-insensitive matching
  • mMultiline - ^ and $ match line starts/ends
  • sDotall - . also matches newlines
  • uUnicode - 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,}$/i

URL

Match HTTP/HTTPS URLs

/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/gi

IPv4 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/g

IPv6 address

Full IPv6 addresses

/([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}/g

ISO 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/g

Time (24-hour)

24-hour time HH:MM or HH:MM:SS

/\b([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?\b/g

Time (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/g

International phone

E.164 international phone format

/\+?[1-9]\d{1,14}/g

Hex color

CSS hex color codes

/#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/gi

Credit card number

16-digit card numbers

/\b(?:\d{4}[\s\-]?){3}\d{4}\b/g

UUID 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/gi

US ZIP code

5 or 9 digit US ZIP

/\b\d{5}(?:-\d{4})?\b/g

Strong 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,}/g

Extract URLs

Find all URLs in text

/https?:\/\/[^\s<>"{}|\\^`\[\]]+/g

Extract IP addresses

Find all IP-like strings

/\b(?:\d{1,3}\.){3}\d{1,3}\b/g

Extract dates

Find date-like patterns

/\b\d{1,4}[-/.]\d{1,2}[-/.]\d{1,4}\b/g

Extract prices

Find currency amounts

/[$£€Β₯]\s?\d+(?:[.,]\d{1,2})?(?:\s?[KkMmBb])?/g

Hashtags

Find hashtags

/#[a-zA-Z][\w]{0,29}/g

Mentions (@user)

Find @mentions

/@[a-zA-Z][\w]{0,29}/g

All numbers

Find all numbers (int or float)

/-?\d+(?:\.\d+)?/g

Trim whitespace

Match leading and trailing whitespace

/^\s+|\s+$/g

Multiple spaces

Match 2+ consecutive spaces

/\s{2,}/g

HTML tags

Match HTML tags for stripping

/<[^>]+>/g

camelCase splitter

Split at camelCase boundaries

/(?<=[a-z])(?=[A-Z])/g

Blank lines

Match empty or whitespace-only lines

/^\s*$/gm

JS line comments

Match // line comments

/\/\/.*$/gm