Created
December 16, 2010 05:56
-
-
Save fatgy/743092 to your computer and use it in GitHub Desktop.
Regular Expression that splits the last line in an address into it's funtional parts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://wiki.cdyne.com/index.php/City_State_Zip_Regex | |
| ^(?<city>[A-Za-z\s]*)(?:,\s?(?<state>[\sA-Za-z]+)|\s(?<state>[A-Za-z]{2})) | |
| (?: | |
| (?:\d{1,4})| | |
| (?<zip>\d{5})(?:-\d{0,3})| | |
| (?<zip>\s\d{5})-(?<zip4>\d{4})| | |
| (?<zip>\s\d{5})| | |
| (?<pc>\s[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d)| | |
| )$ | |
| ///This regular expression will return the following elements of an address: | |
| //* City | |
| // * State/Province (called State in the return) | |
| // * Zip | |
| // * Zip4 - The Zip4 part of the zipcode. | |
| // * PC - This is the Postal Code for Canadian Addresses. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment