Title |
Test
Find
Pattern Title
|
Expression |
^((AL)|(AK)|(AS)|(AZ)|(AR)|(CA)|(CO)|(CT)|(DE)|(DC)|(FM)|(FL)|(GA)|(GU)|(HI)|(ID)|(IL)|(IN)|(IA)|(KS)|(KY)|(LA)|(ME)|(MH)|(MD)|(MA)|(MI)|(MN)|(MS)|(MO)|(MT)|(NE)|(NV)|(NH)|(NJ)|(NM)|(NY)|(NC)|(ND)|(MP)|(OH)|(OK)|(OR)|(PW)|(PA)|(PR)|(RI)|(SC)|(SD)|(TN)|(TX)|(UT)|(VT)|(VI)|(VA)|(WA)|(WV)|(WI)|(WY))$ |
Description |
This validates the states and territories of the United States in a 2 character uppercase format. Very poor excuse for a regular expression! ;)
Written by Jason Gaylord. |
Matches |
NY | PA | NJ |
Non-Matches |
Pennsylvania | Pa | pa |
Author |
Rating:
Jason N. Gaylord
|
Source |
|
Your Rating |
|
Title: Include zip (1-3) to cross verify State and Zip
Name: Lloyd
Date: 2/16/2025 7:23:34 PM
Comment:
How would you implement the regex to cross compare the State abbreviation with the first 3 characters of the base 5 zip code.
Title: Shortened Version
Name: Gavin Kistner
Date: 1/16/2004 3:46:10 PM
Comment:
A[LKSZR]|C[AOT]|D[EC]|F[ML]|G[AU]|HI|I[DLNA]|K[SY]|LA|M[EHDAINSOT]|N[EVHJMYCD]|MP|O[KKR]|P[WAR]|RI|S[CD]|T[NX]|UT|V[TIA]|W[AIVY]
Title: memory
Name: Jakub Skopal
Date: 9/20/2003 5:17:34 AM
Comment:
beware, that every extra () grouping consumes memory and time by catching the match...
@"^(AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY)$" will work the same :-)