EasyRegex Logo
EasyRegex
Nouveau

Match US Zip Codes in JavaScript

javascript

Expression Régulière

\b\d{5}(?:-\d{4})?\b
Copier
Avez-vous des Retours ?

Explication

This regex pattern will match US zip codes. It looks for 5 digits optionally followed by a hyphen and 4 more digits. The \b ensures that the zip code is a whole word.

javascript

Exemple d'Utilisation

const regex = /\b\d{5}(?:-\d{4})?\b/; 
const zipCode = '12345-6789'; 
console.log(zipCode.match(regex));
Copier
Testez l'expression

Expressions Régulières Similaires