EasyRegex Logo
EasyRegex
Nuovo

US Zip Codes

javascript

Espressione Regolare

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

Spiegazione

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

Esempio di Utilizzo

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

Espressioni Regolari Simili