tools / regex library / us zip code
regex pattern · ready to copy

Regex for matching US ZIP codes (5-digit + ZIP+4)

Match both `12345` and `12345-6789` formats. Doesn't enforce real ZIP existence.

intermediate javascript / pcre / python4 use cases

The pattern

\b\d{5}(?:-\d{4})?\b

Test cases

InputResult
94103matches
10001matches
94103-2412matches
20500-0001matches
1234 (4 digits)rejects
94103-12 (4-digit suffix needed)rejects
abc-derejects

Edge cases & caveats

Will match arbitrary 5-digit numbers in text (phone area codes, etc.). Always pair with context (prior `ZIP`, `postal`, address line). For real validation, use USPS database lookup.

Common use cases

Try variations against your data
regexlab is a free in-browser tester with side-by-side match highlighting, group inspector, and named-capture export to JS/Python/PCRE.
Open regexlab  

Related

jwt · url · iso 8601 date · semver version · ↗ generate test addresses