Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
(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])
/
gm

Description

This regex efficiently captures any U.S. state abbreviation in only 117 characters, as opposed to 159 characters to list each state individually.

Submitted by anonymous - 6 years ago