Created
April 26, 2013 07:37
-
-
Save joshuaadickerson/5465556 to your computer and use it in GitHub Desktop.
Match the state code with the string. Should match somerset but not "me" in there.
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
| <?php | |
| // Should match: | |
| $string = 'somerset nj'; | |
| $string = 'nj somerset'; | |
| $string = 'nj'; | |
| $string = 'NJ '; | |
| // Should NOT match | |
| $string = 'somersetnj'; | |
| $string = 'somerset'; | |
| preg_match('/\s?(?:A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])\s?/i', $string, $matches); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just in case this turns up in searches
http://codepad.viper-7.com/crBlzC