EasyRegex Logo
EasyRegex
Neu

Match US Zip Codes in JavaScript

javascript

Regulärer Ausdruck

\b\d{5}(?:-\d{4})?\b
Kopieren
Haben Sie Feedback?

Erklärung

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

Beispielverwendung

const regex = /\b\d{5}(?:-\d{4})?\b/; 
const zipCode = '12345-6789'; 
console.log(zipCode.match(regex));
Kopieren
Testen Sie den Ausdruck

Ähnliche Reguläre Ausdrücke