Skip to main content
Regexflux

US ZIP Code

beginner

Matches US ZIP codes in 5-digit or ZIP+4 format.

zippostalusvalidation

Pattern

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

Try It

0 of 6 strings matched

Explanation

Matches 5-digit US ZIP codes with optional +4 extension (hyphen followed by 4 digits). Word boundaries prevent partial matches.

Test Strings

Matching

  • 90210
  • 10001-1234
  • 00000

Non-matching

  • 1234
  • 123456
  • ABCDE

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOLimited support (ASCII-only word boundaries)

Code Snippets

const regex = /\b\d{5}(?:-\d{4})?\b/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns