US ZIP Code
Match US ZIP codes in 5-digit (12345) and ZIP+4 (12345-6789) formats.
Try it in RegexPro →Available in
Pattern
\b\d{5}(?:[\-\s]\d{4})?\b (flags: g)Raw source: \b\d{5}(?:[\-\s]\d{4})?\b
How it works
Examples
Input
90210Matches
90210
Input
10001-1234Matches
10001-1234
Input
1234No match
—Common use cases
- •Address form validation
- •Shipping/logistics data processing
- •Geographic data extraction
- •E-commerce checkout validation
Related patterns
Canadian Postal Code
ValidationMatch Canadian postal codes in the A1A 1A1 or A1A1A1 format with valid first-letter prefixes.
International Phone Number (Loose)
ValidationMatch international phone numbers in a variety of loose formats including country codes, area codes, and separators.
ISO 3166-1 alpha-2 Country Code
ValidationValidate 2-letter ISO 3166-1 alpha-2 country codes (US, GB, FR, JP, etc.) — structural check only.
ISO 4217 Currency Code
ValidationValidate 3-letter ISO 4217 currency codes (USD, EUR, GBP, JPY, etc.) — structural check only.
Related concepts
Word Boundaries: \b and \B
Concept\b matches the position between a word character and a non-word character. It keeps your regex from matching 'cat' inside 'concatenate.'
How to Match Digits in Regex
How-toUse \d for any digit, [0-9] for ASCII digits only, or {n} to match a specific count of digits. Combine with anchors for whole-string validation.
How to Match an Optional Group
How-toPut a ? after a character, group, or character class to make it optional. Groups with ? match zero or one occurrence of the whole group.
How to Match a Specific Number of Characters
How-toUse {n} for exactly n, {n,} for n or more, {n,m} for between n and m. Apply to any single token — character, class, or group.