InRegex Logo
InRegex
New

US Zip Codes

Explanation

This regex pattern matches US Zip Codes in the format of 5 digits or 5 digits followed by a hyphen and 4 digits. The \b ensures that the zip code is a whole word.

javascript

Regular Expression

\b\d{5}(?:-\d{4})?\b
Copy
Do you have Feedback?
javascript

Example Usage

const regex = /\b\d{5}(?:-\d{4})?\b/g;
const zipCodes = '12345, 54321-6789, 98765'.match(regex);
Copy

Test the expression

Similar Regular Expressions