How to scrape zip code from address

Hello Friends,

Please help me in bellow, I wanted to scrap zip code from below address

Kath Smith
317 County Rd
Torrington, CT 06790-4206

Need OUTPUT: 06790

I want only 06790 in variable

Hi @Bot_Learner

How about the Regular expression?

System.Text.RegularExpressions.Regex.Match(YourString,"\d.*(?=\D\b\d{4}\b)").Tostring

image

Regards
Gokul

1 Like

RegEx

(?<!\d)\d{5}(?!\d)
1 Like

Try using this regular expression \D(\d{5})\D

System.Text.RegularExpressions.Regex.Match(YourString,"\D(\d{5})\D").Tostring
1 Like

@Bot_Learner
(?<=CT\s)(.*?(?=-))

1 Like

Hi @Bot_Learner

Try using the following Regex expression:

[0-9]+(?=-)

Hope it helps!!

Regards,

1 Like

Thanks all @Gokul001 @postwick @aquinn @raja.arslankhan @Parvathy for reply …could you plz let me know…how can i extract state name…like CT in above example…everytime time i have different sate of 2 letters only.

Google is your friend on these things.

https://www.google.com/search?q=regex+to+get+2+letter+state+from+address

1 Like

Hi @Bot_Learner

Use this regex to scrap state name

System.Text.RegularExpressions.Regex.Match(inputString, “(?<=\b)[A-Z]{2}(?=\s\d)”).Value

Thanks!!

1 Like

@Nitya1 thanks for u r response.

1 Like

@postwick sir i dont know how to use it…but i extracted state name by split string

You can do that as long as the address is always formatted exactly the same.

Hi @Bot_Learner

Try using the following regex expression

[A-Z]+\s

Hope it helps!!

Regards,

check this post

looks related for your request

Regards