Regex for US ZIP code
/\b\d{5}(?:-\d{4})?\b/g
Matches
Examples
Note
Five digits, optionally with a ZIP+4 extension. It cannot tell a ZIP from any other five-digit number.
Matches in the example
"94103""10001-1234"
Token by token
\ba word boundary\d{5}a digit (0–9), exactly 5 times(?:a group, not capturing-the character “-”\d{4}a digit (0–9), exactly 4 times)?end of group, whole group optionally\ba word boundary
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma