Which pattern matches a US ZIP code like 12345 or 12345-6789?
/^\d{5}(-\d{4})?$//^\d{5}-\d{4}$//^\d{5}(-\d{4})*//\d{5}|\d{4}$/
The optional group
Play Regex ▸
(-\d{4})? allows the +4 suffix, and both anchors reject extra characters.