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.
const regex = /\b\d{5}(?:-\d{4})?\b/;
const zipCode = '12345-6789';
console.log(zipCode.match(regex));
Copiar