EasyRegex Logo
EasyRegex
Neu

Match American Zip Code

Javascript

Regulärer Ausdruck

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

Erklärung

This regex pattern matches American zip codes. It starts with a word boundary \b, followed by 5 digits \d{5}. It then optionally matches a hyphen and 4 digits (?:-\d{4}) before ending with another word boundary \b.

Javascript

Beispielverwendung

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

Ähnliche Reguläre Ausdrücke