Skip to the tester

Common regex patterns

The patterns everyone ends up needing, stated honestly with their limits. Copy any of them, or load one into the tester at the bottom via its link.

Email address

Load in tester ↓
\b[\w.+-]+@[\w-]+\.[\w.]{2,}\b

Good for finding addresses in text and catching form typos. Limits: no unicode domains, and full RFC addresses cannot be regex-validated, confirm by sending.

\b[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}\b

Covers all six UK postcode shapes, space optional, add the i flag for lowercase. Limits: shape only, it cannot know whether the postcode is actually allocated.

URL (http and https)

Load in tester ↓
https?:\/\/[\w.-]+(?:\/[^\s"'<>]*)?

Finds web links in prose without swallowing the closing quote or bracket around them. Limits: trailing punctuation like a full stop after the link is included; trim in code.

IPv4 address

Load in tester ↓
\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b

Each octet is genuinely constrained to 0-255, so 999.1.1.1 fails. Limits: IPv4 only; IPv6 needs its own, much longer pattern.

Date, DD/MM/YYYY

Load in tester ↓
\b(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/(\d{4})\b

Days capped at 31, months at 12, with capture groups ready for reordering ($3-$2-$1 gives ISO). Limits: 31/02 still passes, calendars need code, not regex.

The tester

Click any Load in tester link above and the pattern, flags and sample text drop straight in via the URL fragment.

FAQ

Frequently asked questions

Is there a perfect email regex?

No. The address spec allows things no pattern should accept in a form. The practical approach: a simple pattern to catch typos, then confirm the address by sending to it.

Why is the UK postcode pattern so long?

UK postcodes have six valid shapes (A9 9AA through AA9A 9AA). The pattern accepts all six with or without the space; uppercase the input first or add the i flag.

Why does the IPv4 pattern have all those alternatives?

Each octet must be 0-255, which plain \d{1,3} cannot express: it would accept 999. The alternation spells out 25x, 2xx, and everything below.

Should I validate dates with regex?

Regex checks the shape, not the calendar: 31/02/2026 passes a format check. Match the format with regex, then confirm the date is real in code.

Can I use these patterns in my language?

These are JavaScript-flavour patterns and all avoid exotic features, so they work as-is in Python, Go, Java and most languages. Test in your runtime for edge cases.

Why do the patterns look conservative?

Deliberately. A pattern that over-accepts fails silently in production; one that is honest about limits fails visibly in testing. Each card states what its pattern does not catch.

More tools

Related tools

Regex testerBuild your own pattern from scratch. Regex cheat sheetWhat every token in these patterns means. JSON to CSVGet extracted data into a spreadsheet.
Skip to the tester

Common regex patterns

The patterns everyone ends up needing, stated honestly with their limits. Copy any of them, or load one into the tester at the bottom via its link.

Email address

Load in tester ↓
\b[\w.+-]+@[\w-]+\.[\w.]{2,}\b

Good for finding addresses in text and catching form typos. Limits: no unicode domains, and full RFC addresses cannot be regex-validated, confirm by sending.

\b[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}\b

Covers all six UK postcode shapes, space optional, add the i flag for lowercase. Limits: shape only, it cannot know whether the postcode is actually allocated.

URL (http and https)

Load in tester ↓
https?:\/\/[\w.-]+(?:\/[^\s"'<>]*)?

Finds web links in prose without swallowing the closing quote or bracket around them. Limits: trailing punctuation like a full stop after the link is included; trim in code.

IPv4 address

Load in tester ↓
\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b

Each octet is genuinely constrained to 0-255, so 999.1.1.1 fails. Limits: IPv4 only; IPv6 needs its own, much longer pattern.

Date, DD/MM/YYYY

Load in tester ↓
\b(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/(\d{4})\b

Days capped at 31, months at 12, with capture groups ready for reordering ($3-$2-$1 gives ISO). Limits: 31/02 still passes, calendars need code, not regex.

The tester

Click any Load in tester link above and the pattern, flags and sample text drop straight in via the URL fragment.

2 matches.

hello@woldscyber.co.uk, not-an-email@localhost, sam.o'brien+tag@mail.example.org

Matches and groups

#1 at 0 hello@woldscyber.co.uk
#2 at 54 brien+tag@mail.example.org
The link stores pattern, flags and text in the URL fragment, which never reaches any server.

Everything runs in your browser using the JavaScript regex engine. Nothing you test is sent anywhere.

FAQ

Frequently asked questions

Is there a perfect email regex?

No. The address spec allows things no pattern should accept in a form. The practical approach: a simple pattern to catch typos, then confirm the address by sending to it.

Why is the UK postcode pattern so long?

UK postcodes have six valid shapes (A9 9AA through AA9A 9AA). The pattern accepts all six with or without the space; uppercase the input first or add the i flag.

Why does the IPv4 pattern have all those alternatives?

Each octet must be 0-255, which plain \d{1,3} cannot express: it would accept 999. The alternation spells out 25x, 2xx, and everything below.

Should I validate dates with regex?

Regex checks the shape, not the calendar: 31/02/2026 passes a format check. Match the format with regex, then confirm the date is real in code.

Can I use these patterns in my language?

These are JavaScript-flavour patterns and all avoid exotic features, so they work as-is in Python, Go, Java and most languages. Test in your runtime for edge cases.

Why do the patterns look conservative?

Deliberately. A pattern that over-accepts fails silently in production; one that is honest about limits fails visibly in testing. Each card states what its pattern does not catch.

More tools

Related tools