Title |
Test
Find
Validate US Postal Code
|
Expression |
^(?!00000)(?<zip>(?<zip5>\d{5})(?:[ -](?=\d))?(?<zip4>\d{4})?)$ |
Description |
Validate US zip codes. Matches all zip codes of exactly 5 digits except 00000. Optionally, matches zip5+zip4 where zip5 is exactly 5 digits, zip4 is exactly 4 digits, and zip5 and zip4 are, optionally, separated by a single space or hyphen. Captures zip5 and zip4 to named groups to facilitate program manipulation. |
Matches |
12345 | 123456789 | 12345-6789 |
Non-Matches |
12345- | 00000 | 00000-6789 |
Author |
Rating:
Not yet rated.
Jerry Schmersahl
|
Source |
|
Your Rating |
|
Title: Pattern failure
Name: Hardryv
Date: 9/5/2006 6:24:56 PM
Comment:
parsing "^(?!00000)(?\d{5})(?:(?:[- ]?)(?\d{4}))?$" - Unrecognized grouping construct
I had high hopes that this pattern would not only lead me to a solution, but also teach me something. For some reason it failed when tested. Can you please fix it or advise me what switches you ran it with to test it please?