Pattern Library

A curated collection of industry-standard regular expressions for common validation and extraction tasks.

Common Validation

Email Address

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Validates standard email formats including subdomains.

IPv4 Address

^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$

Matches standard IPv4 notation (0-255 range not strictly enforced here).

Strong Password

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

Min 8 chars, 1 uppercase, 1 lowercase, 1 number, 1 special char.

Web & Text Extraction

URL (HTTP/HTTPS)

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

Extracts full URLs with optional query parameters.

HTML Tags

<([a-z1-6]+)([^>]+)*>(.*?)<\/\1>

Matches balanced HTML tags and captures content.

Dates (YYYY-MM-DD)

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$

Standard ISO date format validation.

Understanding Pattern Construction

Every pattern in this library follows a specific architecture. A well-constructed regex should be both performant and readable. While it's tempting to write "clever" patterns, maintainability is key in professional development.

The Anatomy of a Pattern

Most of the patterns above use Lookaheads (e.g., `(?=...)`). Lookaheads are powerful because they allow you to check for a condition without "consuming" characters in the match. This is essential for password validation where you need to check for multiple independent criteria within the same string.

Another critical concept is Greediness. By default, quantifiers like `*` and `+` are greedy—they match as much as possible. Adding a `?` after them (e.g., `*?`) makes them lazy, which is vital when matching HTML tags or quotes to prevent matching from the first tag to the very last one in a document.