🔍

Regex Recipes

Ready-to-use regular expression patterns for common validation and extraction tasks

35 templates

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,}$
5 examples 2 code snippets

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()@:%_\+.~#?&\/\/=]*)$
5 examples 1 code snippets

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})$
5 examples 2 code snippets

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}$
4 examples 2 code snippets

URL Slug Validation

Validate URL-friendly slugs with lowercase letters, numbers, and hyphens.

^[a-z0-9]+(?:-[a-z0-9]+)*$
5 examples 1 code snippets

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])$
5 examples 1 code snippets

Email Validation (Permissive)

Very permissive email pattern for loose input acceptance. Use when you want to avoid false rejections.

^.+@.+\..+$
5 examples 1 code snippets

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]$
5 examples 1 code snippets

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]?)$
5 examples 2 code snippets

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}:)$
4 examples 1 code snippets

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])$
6 examples 1 code snippets

Username (Safe)

Safe username validation with letters, numbers, dots, underscores, and hyphens with length rules.

^[a-zA-Z0-9._-]{3,20}$
5 examples 1 code snippets

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,}$
5 examples 1 code snippets

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]$
5 examples 1 code snippets

Extract Text Between Quotes

Extract content between double quotes with greedy vs lazy matching examples.

"([^"]*)"
4 examples 1 code snippets

Extract Content Inside Parentheses

Extract text inside parentheses with nested limitation notes.

\(([^)]*)\)
4 examples 1 code snippets

Remove Duplicate Spaces

Find and replace multiple consecutive spaces with a single space.

{2,}
3 examples 1 code snippets

Trim Leading/Trailing Whitespace

Remove whitespace from start and end of lines with multiline variations.

^\s+|\s+$
4 examples 1 code snippets

Find Trailing Spaces

Detect trailing whitespace at end of lines for code cleanup.

+$
3 examples 1 code snippets

Detect Repeated Words

Find accidentally repeated words like "the the" in text.

\b(\w+)\s+\1\b
4 examples 1 code snippets

Find TODO/FIXME Comments

Scan code for TODO, FIXME, HACK, and NOTE comments.

(TODO|FIXME|HACK|NOTE|XXX):?\s*(.*)$
3 examples 1 code snippets

Credit Card Format (Luhn Disclaimer)

Match credit card number formats. WARNING: Format match only - must run Luhn algorithm separately for validation.

^\d{13,19}$
3 examples 1 code snippets

Phone Number (E.164 International)

Validate international phone numbers in E.164 format (+country code without spaces).

^\+[1-9]\d{1,14}$
5 examples 1 code snippets

Serbian Phone Numbers

Validate Serbian phone numbers with local format patterns.

^(\+381|0)[1-9]\d{7,8}$
4 examples 1 code snippets

ZIP/Postal Code (Generic)

Generic postal code validation with country-specific notes.

^[A-Z0-9]{3,10}$
4 examples 1 code snippets

HTML Tag Stripper (WARNING)

Basic HTML tag removal pattern. WARNING: Regex cannot reliably parse HTML - use proper HTML parser.

<[^>]+>
3 examples 1 code snippets

Markdown Heading Detection

Detect markdown headings with ATX-style # syntax.

^#{1,6}\s+.+$
5 examples 1 code snippets

Extract Hashtags

Extract social media hashtags with Unicode support for international characters.

#[\w\u00C0-\u017F]+
5 examples 1 code snippets

Extract @Mentions

Extract social media @mentions and @usernames from text.

@[\w]{1,15}
4 examples 1 code snippets

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-]+)*))?$
4 examples 1 code snippets

File Extension Whitelist

Validate file extensions against a whitelist of allowed types.

\.(jpg|jpeg|png|gif|webp)$
4 examples 1 code snippets

Windows Path (Basic)

Match Windows file paths with drive letter and backslashes. Includes escaping examples.

^[A-Za-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$
3 examples 1 code snippets

Unix Path (Basic)

Match Unix/Linux file paths for both absolute and relative paths.

^(/)?([^/\0]+(/)?)+$
5 examples 1 code snippets

Base64 Detection

Detect Base64-encoded strings with padding variation support.

^[A-Za-z0-9+/]+={0,2}$
4 examples 1 code snippets

Detect Non-ASCII Characters

Find characters outside ASCII range (0-127) for text sanitization.

[^\x00-\x7F]
4 examples 1 code snippets