Developer Pattern Library & Syntax Reference

Common Regular Expressions (RegEx) Library

Production-tested regular expressions for client-side forms, backend validation, and data extraction. Tested across JavaScript, Python, Go, PHP, and Java with sample matches and flag explanations.

VALIDATIONflags: /i

Email Address Validation Regex

Standard RFC-compliant email address validation pattern for form inputs.

/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i
Match: developer@example.comView Details
SECURITY

Strong Password Policy Regex

Enforces minimum 8 chars, at least 1 uppercase, 1 lowercase, 1 digit, and 1 special symbol.

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
Match: P@ssw0rd2026!View Details
WEBflags: /i

HTTP/HTTPS URL Validation Regex

Validates web URLs including domain, optional port, and query parameter path.

/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/i
Match: https://devtransform-hub.vercel.app/tools/View Details
SECURITY

IPv4 Address Validation Regex

Validates standard dotted decimal IPv4 network address within range 0.0.0.0 to 255.255.255.255.

/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
Match: 192.168.1.1View Details
VALIDATIONflags: /i

UUID v4 Identifier Validation Regex

Validates 36-character canonical random UUID version 4 format.

/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
Match: f47ac10b-58cc-4372-a567-0e02b2c3d479View Details
WEBflags: /i

Hex Color Code Regex (#RGB and #RRGGBB)

Matches 3-digit or 6-digit CSS hexadecimal color notation.

/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/i
Match: #10b981View Details
WEB

SEO Friendly URL Slug Regex

Enforces lowercase alphanumeric words separated only by single hyphens with no trailing dashes.

/^[a-z0-9]+(?:-[a-z0-9]+)*$/
Match: universal-developer-tools-2026View Details
FORMATTING

US Phone Number Format Regex

Validates 10-digit North American telephone numbers in formats like (123) 456-7890 or 123-456-7890.

/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
Match: (555) 234-5678View Details
FORMATTING

ISO 8601 Date (YYYY-MM-DD) Regex

Matches standard ISO year-month-day calendar dates.

/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
Match: 2026-09-04View Details
SECURITY

JSON Web Token (JWT) Format Regex

Validates structure of Base64URL-encoded Header.Payload.Signature JWT strings.

/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/
Match: eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozGzN_ce9Trqnh9xsmvrmA6Y8b0VfP_w1sL8sRView Details
VALIDATION

Semantic Versioning (SemVer) Regex

Validates official Semantic Versioning 2.0.0 strings including pre-release and build metadata.

/^v?(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-]+)*))?$/
Match: v2.4.1-alpha.3+build.2026View Details
VALIDATION

Base64 Encoded String Validation Regex

Validates standard RFC 4648 Base64 encoded strings with valid length multiples of 4 and padding.

/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/
Match: SGVsbG8gV29ybGQhView Details
FORMATTING

Hexadecimal Color Code (#HEX) Regex

Matches 3-digit shorthand, 6-digit RGB, or 8-digit RGBA hex color codes.

/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/
Match: #10b981View Details
VALIDATION

Credit Card Number (Visa / Master / Amex) Regex

Validates primary card major industry identifiers for Visa, MasterCard, American Express, and Discover.

/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$/
Match: 4111111111111111View Details
FORMATTING

Hardware MAC Address Regex

Matches standard 48-bit physical MAC addresses formatted with colons or hyphens.

/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/
Match: 00:1A:2B:3C:4D:5EView Details
VALIDATION

TCP / UDP Network Port (1-65535) Regex

Validates network port numbers strictly between 1 and 65,535.

/^([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])$/
Match: 8080View Details
VALIDATION

Git Commit Hash (SHA-1 / SHA-256) Regex

Matches short (7-char) and full (40-char SHA-1) Git commit hashes.

/^[0-9a-fA-F]{7,40}$/
Match: 7075d8aView Details
VALIDATION

CUID & CUID2 Collision-Resistant ID Regex

Validates modern secure collision-resistant identifiers (CUID and CUID2) used in high-scale distributed systems.

/^[a-z0-9]{24,32}$/
Match: cl01abcde000001l0abcdefghView Details
VALIDATION

5-Field Unix Cron Expression Regex

Validates standard 5-to-7 field crontab expressions including wildcard, ranges, steps, and shortcuts.

/^(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|Β΅s|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})$/
Match: */15 0 1,15 * 1-5View Details
VALIDATION

NanoID (21-character) URL-Friendly ID Regex

Validates default 21-character URL-friendly, compact NanoID strings.

/^[A-Za-z0-9_-]{21}$/
Match: V1StGXR8_Z5jdHi6B-myTView Details
WEBflags: /i

YouTube Video ID & URL Extractor Regex

Matches YouTube video URLs and captures the 11-character unique video identifier.

/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w-]{11})(?:\S+)?$/i
Match: https://www.youtube.com/watch?v=dQw4w9WgXcQView Details
WEBflags: /g

HTML Opening & Closing Tag Stripper Regex

Finds and strips opening, closing, and self-closing HTML/XML markup tags from rich text strings.

/<\/?[a-zA-Z][^>]*>/g
Match: <div class="active" data-id="10">View Details
WEBflags: /g

Markdown Image Syntax Regex

Extracts alt text, image URL, and optional title from standard Markdown image tags.

/!\[([^\]]*)\]\(([^\s)]+)(?:\s+"([^"]+)")?\)/g
Match: ![Company Logo](https://example.com/logo.png "Brand")View Details
VALIDATION

Semantic Versioning (SemVer 2.0.0) Regex

Official SemVer 2.0.0 regular expression supporting MAJOR.MINOR.PATCH, prerelease identifiers, 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-]+)*))?$/
Match: 2.1.0-alpha.1+build.847View Details
VALIDATION

Docker Image Repository & Tag Name Regex

Validates complete Docker image references including optional registry domain, namespace, image name, and tag.

/^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[\w][\w.-]{0,127})?$/
Match: ghcr.io/org/service-app:v1.4.2View Details
FORMATTING

Un-hyphenated 32-Char Hexadecimal UUID Regex

Validates 32-character compact hexadecimal UUIDs/GUIDs stripped of standard hyphen delimiters.

/^[0-9a-fA-F]{32}$/
Match: e7236c525b5b444da6428c3ed5a29340View Details
SECURITYflags: /i

SQL Injection Attack Detection Heuristic Regex

Detects common SQL injection attack signatures, comments, and dangerous stored procedures in user inputs.

/(?i)(?:\b(select|union|insert|update|delete|drop|alter|create|truncate|exec|execute)\b|--|/\*|\*/|xp_cmdshell|\bwaitfor\s+delay\b)/i
Match: 1' UNION SELECT username, password FROM users --View Details
WEBflags: /i

IPv6 Address Validation Regex

Validates standard, compressed, and IPv4-mapped IPv6 network addresses compliant with RFC 4291.

/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/i
Match: 2001:0db8:85a3:0000:0000:8a2e:0370:7334View Details
VALIDATION

International E.164 Phone Number Regex

Strict ITU-T E.164 international phone number format beginning with plus sign followed by 2 to 15 digits.

/^\+[1-9]\d{1,14}$/
Match: +14155552671View Details
VALIDATIONflags: /i

United Kingdom Phone Number Regex

Comprehensive United Kingdom mobile, landline, and national dialing format validator.

/^(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?(?:\(?0\)?[\s-]?)?)|(?:\(?0))(?:(?:\d{5}\)?[\s-]?\d{4,5})|(?:\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3}))|(?:\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4})|(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}))(?:[\s-]?(?:x|ext\.?)[\s-]?\d{1,5})?$/i
Match: +44 7911 123456View Details
SECURITY

Visa Credit Card Number Regex

Matches 13-digit and standard 16-digit Visa debit and credit card numbers starting with 4.

/^4[0-9]{12}(?:[0-9]{3})?$/
Match: 4111111111111111View Details
SECURITY

Mastercard Credit Card Number Regex

Validates 16-digit Mastercard card numbers across traditional 51-55 series and 2221-2720 2-series ranges.

/^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/
Match: 5500000000000004View Details
SECURITY

American Express (Amex) Card Regex

Validates 15-digit American Express credit cards starting with prefixes 34 or 37.

/^3[47][0-9]{13}$/
Match: 378282246310005View Details
FORMATTING

ISO 8601 UTC / Timestamp Regex

Matches standard ISO 8601 and RFC 3339 formatted timestamps including millisecond precision and UTC/timezone offsets.

/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/
Match: 2026-09-20T02:45:00.000ZView Details
FORMATTING

24-Hour Time (HH:mm) Regex

Validates 24-hour military and European clock time from 00:00 through 23:59.

/^(?:[01]\d|2[0-3]):[0-5]\d$/
Match: 23:59View Details
FORMATTING

12-Hour Time with AM/PM Regex

Validates standard 12-hour time formats with case-insensitive AM or PM indicators.

/^(?:1[0-2]|0?[1-9]):[0-5]\d\s*(?:[AaPp][Mm])$/
Match: 11:45 PMView Details
VALIDATION

United States Postal ZIP Code Regex

Matches 5-digit US ZIP codes and standard 9-digit ZIP+4 formats (12345 or 12345-6789).

/^\d{5}(?:-\d{4})?$/
Match: 94016-1234View Details
VALIDATIONflags: /i

United Kingdom Postcode Regex

Validates official UK postcodes across all outward and inward alphanumeric sectors.

/^[A-Z]{1,2}[0-9][A-Z0-9]? ?[0-9][A-Z]{2}$/i
Match: SW1A 1AAView Details
VALIDATIONflags: /i

Canada Postal Code Regex

Validates Canadian postal codes adhering to official Canada Post character exclusions (excludes D, F, I, O, Q, U).

/^[A-CEGHJ-NPR-TVXY]\d[A-CEGHJ-NPR-TV-Z] ?\d[A-CEGHJ-NPR-TV-Z]\d$/i
Match: K1A 0B1View Details
SECURITY

Bitcoin (BTC) Address Regex

Validates Bitcoin Legacy (P2PKH starting with 1), SegWit P2SH (starting with 3), and Native SegWit (Bech32 starting with bc1) wallet addresses.

/^(?:1[a-km-zA-HJ-NP-Z1-9]{25,34}|3[a-km-zA-HJ-NP-Z1-9]{25,34}|bc1[a-zA-HJ-NP-Z0-9]{25,39})$/
Match: bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdqView Details
SECURITY

Ethereum (ETH) Address Regex

Validates Ethereum and EVM-compatible (Polygon, Arbitrum, BSC) public account and contract hexadecimal addresses.

/^0x[a-fA-F0-9]{40}$/
Match: 0x71C8451C3343244F0080644085429188e7D4d715View Details
WEB

Twitter / X Username Handle Regex

Validates Twitter and X user handles, allowing an optional leading @ symbol and up to 15 alphanumeric or underscore characters.

/^@?[a-zA-Z0-9_]{1,15}$/
Match: @devtransformView Details
WEB

GitHub Username Regex

Strictly complies with GitHub username rules: max 39 chars, alphanumeric, single internal hyphens, no consecutive hyphens, cannot start or end with a hyphen.

/^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9])){0,38}$/
Match: ensibeyView Details
WEB

Fully Qualified Domain Name (FQDN) Regex

RFC 1035 compliant domain name and hostname validator preventing leading/trailing hyphens in labels.

/^(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.(?:[A-Za-z]{2,}|(?:[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,})$/
Match: api.devtransform-hub.vercel.appView Details
WEBflags: /i

Subdomain Extraction Regex

Captures and isolates the third-level subdomain prefix from a full hostname or URL.

/^(?:https?:\/\/)?([a-zA-Z0-9-]+)\.[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/i
Match: https://staging.example.comView Details
FORMATTINGflags: /i

File Extension Extraction Regex

Isolates the trailing file extension from local paths, URLs, or document names while safely ignoring query strings and hashes.

/\.([a-zA-Z0-9]+)(?:\?|#|$)/i
Match: /uploads/invoice_report.pdf?version=2View Details
FORMATTINGflags: /i

CSS RGB / RGBA Color Function Regex

Matches valid CSS rgb(255, 255, 255) and rgba(0, 0, 0, 0.5) declarations restricting channels to 0-255.

/^rgba?\(\s*(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\s*,\s*(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\s*,\s*(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\s*(?:,\s*(?:0|1|0?\.\d+)\s*)?\)$/i
Match: rgba(16, 185, 129, 0.85)View Details
FORMATTINGflags: /i

CSS HSL / HSLA Color Function Regex

Validates CSS hsl() and hsla() syntax, clamping hue to 0-360 and saturation/lightness to 0%-100%.

/^hsla?\(\s*(?:360|3[0-5]\d|[12]?\d{1,2})\s*,\s*(?:100|[1-9]?\d)%\s*,\s*(?:100|[1-9]?\d)%\s*(?:,\s*(?:0|1|0?\.\d+)\s*)?\)$/i
Match: hsl(142, 70%, 45%)View Details
FORMATTINGflags: /g

HTML Attribute Value Extractor Regex

Extracts HTML attribute key-value pairs (e.g., href="...", class="...", data-id="...") from markup tags.

/\b([a-zA-Z-]+)=["\']([^"\']+)["\']/g
Match: href="https://devtransform-hub.vercel.app" class="text-brand"View Details
FORMATTINGflags: /g

Markdown Link Extractor Regex

Parses and extracts markdown hyperlink text labels and target destination URLs [Title](https://...).

/\[([^\]]+)\]\((https?:\/\/[^\s\)]+)\)/g
Match: [DevTransform Suite](https://devtransform-hub.vercel.app)View Details
FORMATTINGflags: /g

CamelCase Word Boundary Regex

Identifies transitional word boundaries in camelCase and PascalCase identifiers to convert strings into snake_case or kebab-case.

/([a-z0-9])([A-Z])/g
Match: devTransformHubView Details
FORMATTINGflags: /i

Duplicate Consecutive Word Regex

Finds accidental repeated words in editorial prose and code comments (e.g., "the the", "in in").

/\b([a-zA-Z]+)\s+\1\b/i
Match: This is the the best toolView Details
FORMATTINGflags: /g

Leading & Trailing Whitespace Regex

Targets superfluous leading and trailing spaces or tab characters across string lines for clean sanitization.

/^\s+|\s+$/g
Match: untrimmed developer input View Details
FORMATTINGflags: /g

C-Style Code Comment Regex

Matches single-line (//) and multi-line (/* ... */) code comments across JavaScript, C, Java, Go, and PHP.

/\/\*[\s\S]*?\*\/|\/\/.*/g
Match: /* Multi-line comment block */ // single line commentView Details
FORMATTINGflags: /g

JSON Key-Value Pair Extractor Regex

Extracts property keys and primitive values (strings, numbers, booleans, null) from JSON data strings.

/"([^"]+)"\s*:\s*("[^"]*"|\d+(?:\.\d+)?|true|false|null)/g
Match: "status": 200, "isClient": true, "name": "DevTransform"View Details

Regular Expression Syntax Quick Reference

Core metacharacters, quantifiers, and assertion syntax

TokenDescriptionExample
^ / $Start of line / End of line anchors^https?
\d / \DAny digit [0-9] / Any non-digit\d4-\d2-\d2
\w / \WWord character [a-zA-Z0-9_] / Non-word^\w+$
\s / \SWhitespace character (space, tab, newline) / Non-whitespace\s+
*, +, ?0 or more (*), 1 or more (+), 0 or 1 optional (?)colou?r
(?=...)Positive lookahead assertion (must be followed by ...)(?=.*[A-Z])

Frequently Asked Questions About Regular Expressions

Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

For general web form validation, `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$` provides the optimal balance between strictness and compatibility without rejecting valid modern domains.