EasyRegex Logo
EasyRegex
Nuevo

Match US Zip Codes in JavaScript

javascript

Expresión Regular

\b\d{5}(?:-\d{4})?\b
Copiar
¿Tienes Comentarios?

Explicación

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

Ejemplo de Uso

const regex = /\b\d{5}(?:-\d{4})?\b/; 
const zipCode = '12345-6789'; 
console.log(zipCode.match(regex));
Copiar
Prueba la expresión

Expresiones Regulares Similares