Common Regex Patterns

Use a pattern as a starting point, then test it in your target engine. Matching a format does not prove that an address, date or account is valid.

Runs locally in your browser
Use caseRegular expressionNotes
Email address ^[^\s@]+@[^\s@]+\.[^\s@]+$ Practical syntax check; delivery requires verification.
HTTP or HTTPS URL ^https?:\/\/[^\s]+$ Checks the scheme and rejects whitespace; use a URL parser for full validation.
IPv4 address ^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$ Accepts octets from 0 through 255.
UUID versions 1–5 ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$ Checks the standard hyphenated form and RFC variant bits.
ISO-style date ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ Checks YYYY-MM-DD shape, not month-specific day limits.
24-hour time ^(?:[01]\d|2[0-3]):[0-5]\d$ Accepts values from 00:00 through 23:59.
Hex color ^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$ Supports RGB, RRGGBB, and RRGGBBAA notation.
Semantic version ^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$ Matches core versions plus optional prerelease and build metadata.
Signed integer ^-?\d+$ Allows an optional minus sign.
Decimal number ^-?(?:\d+|\d*\.\d+)$ Accepts integers and decimal fractions, including values such as .5.
URL slug ^[a-z0-9]+(?:-[a-z0-9]+)*$ Lowercase ASCII words separated by single hyphens.
HTML-like tag <\/?[A-Za-z][^>]*> Useful for simple extraction only; parse HTML with an HTML parser.
Leading or trailing whitespace ^\s+|\s+$ Use the global flag when removing whitespace from both ends.
Blank line ^\s*$ Use multiline mode to evaluate each line separately.
Repeated adjacent word \b([A-Za-z]+)\s+\1\b Use case-insensitive mode if capitalization should be ignored.

Portability notes

JavaScript, PCRE, Python, Java, .NET, Go, and Ruby do not implement exactly the same regex features. Check the target engine before relying on lookbehind, named groups, Unicode properties, possessive quantifiers, or inline modifiers.

For security-sensitive validation, normalize the input first, apply explicit length limits, and use a dedicated parser whenever the data format has one.

Recent tools: