Orbitautil
Regex Reference

Regex Examples

Six patterns for common inputs. Each one was run in JavaScript and Python against inputs that should and should not match, and the note under it says what it accepts and what it rejects. Open any of them in the tester to try your own text. In Python, use re.fullmatch (with $ a trailing newline still passes) and the re.ASCII flag (without it, \d also matches digits from other scripts).

URL (HTTP/HTTPS)

Matches http:// and https:// addresses with a domain or IPv4 host and an optional path or query. It rejects localhost, other schemes such as ftp://, spaces and paths with characters such as , ; ! * ' or $, and it accepts out-of-range IPs such as 999.999.999.999.

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

Strong Password

Requires at least 8 characters with a lowercase letter, an uppercase letter, a digit and one of @$!%*?&. Any other symbol, such as # or a space, makes it fail, so widen the last character class if your rules allow them.

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

IPv4 Address

Checks four numbers from 0 to 255 separated by dots. It also accepts leading zeros such as 01.02.03.004.

^(?:(?: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]?)$
Test in Editor

Date (YYYY-MM-DD)

Matches the YYYY-MM-DD shape with months 01–12 and days 01–31. It does not check how many days each month has, so 2026-02-31 passes: validate the real date in code.

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

Hex Color Code

Matches 3- or 6-digit hex colors, with or without the leading #. Colors with an alpha channel (#RRGGBBAA) do not match.

^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
Test in Editor

Frequently asked questions

Why is email validation with regex so complex?

The official RFC 5322 standard for email addresses is extremely permissive, allowing many obscure formats. For most applications, a simplified regex that checks for a string, an @ symbol, and a domain is preferred.

Should I use regex to parse HTML?

No. Regular expressions are not designed to parse nested structures like HTML or XML. It's highly recommended to use a dedicated HTML parser instead.