I need to find State abbreviations in column name my_column. This column can contain values like these
John Smith of AZ --> Match
John Smith of AZ(Tucson)' --> Match
AZ John Smith --> Match
John Smith AZ for Tucson --> Match
Utah Jazz --> Don't Match
Azyme --> Don't Match
'Hazy --> Don't Match
I tried using CASE expressions with CHARINDEX and LIKE to do all this matching, but it is getting super-ugly. I wonder if there is a better way.
I asked our DBA to install Full-Text Index to see if I can do something better with CONTAINS, but not sure if it really helps.
\b(AL|AK|AZ|AR|...|WI|WY)\b.\bmatches word boundaries, so it won't matchJazzorAzyme' ' + column + ' ' like '%[ (),]AZ[ (),]%'for multiple abbrev you can just join a table containing thoseRegex(such asTRANSLATEthat could be used to replace all the word boundary characters with a consistent character prior to splitting)