$ ./guess_the_languageRegex
Regex · medium · #53

Which pattern matches a US ZIP code like 12345 or 12345-6789?

  1. /^\d{5}(-\d{4})?$/
  2. /^\d{5}-\d{4}$/
  3. /^\d{5}(-\d{4})*/
  4. /\d{5}|\d{4}$/
The optional group (-\d{4})? allows the +4 suffix, and both anchors reject extra characters.
Play Regex ▸