Regular Expression code

I have attached a .txt file of loss information sample data. Im trying to write a regual expression that will take the state and the zipcode. The autoamtion runs through emails that have this type of information. What would be a good regular expression to get the state from each loss information and another to get the zipcode from the loss information?

Regular Expression.txt (729 Bytes)
[Regular Expression.txt|attachment]

(upload://jPIxzgmZiCd6YI7o4NR711JXLFB.txt) (729 Bytes)


Check below for your reference

Regex:(?<=, ).+

Hope this may help you


That may not work if there are other commas used elsewhere. Also it doesn’t separate state and zip into 2 different matches.

Here’s a more accurate pattern for the state:

(?<=, )\w{2}(?= \d{5})

Here’s the pattern for the zip:

(?<=, \w{2} )\d{5}
1 Like

Hi Nathan. More precise regex should include possible values in state abreviation. Use the following:


Hope it helps!

Thanks for this i was just having a issue with this, i would i implement this code?

When i do fetch the state for example CA for California i have to add that in a state box. the issue is the state box wants the full state name. so if i pull the state CA from the text file i have to type the state California in the text box. Any ideas ?

Sorry. I’ve just corrected it

Populate a dictionary of State Names using abbreviation as key, so when you have to input state you get that value

This code takes the Stat and the zip is there a way it can just take the state and not the zip?

Yes, remove the last part \s\d{5}

How would i populate a dictionary to achieve this issue?

Here is an example


It works with this excel file

us_states.xlsx (9.7 KB)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.