Regex Expression to find city and zip from address

Hi,
I want to find City Name and ZIP only from following , Need regular expression

2055 Niagara Falls Blvd, Amherst NY 14228
101 Sanford Farm Shpg Center, Amsterdam NY 12010
830 Curran Memorial Hwy, North Adams MA 1247

@Ritesh_R Can you Maybe highlight what needs to be extracted :sweat_smile:

Hi @Ritesh_R

Can you specify the output that from the text which nos are ZIP and which city are trying to extract ??

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Last 5 Nos are Zip and before that , its city name

Hi @Ritesh_Ralekar,

The easiest way to get all your arithmetic from a text is \d+ . Then you can choose the ZIP and the city code.
regex

830 Curran Memorial Hwy, North Adams MA 1247

Highlighted, need output from number of addresses

Hi,

Hope the following helps you.

Zip

System.Text.RegularExpressions.Regex.Match(text,"\d+$").Value

State and Zip

System.Text.RegularExpressions.Regex.Match(text,"[A-Z]+\s\d+$").Value

City

System.Text.RegularExpressions.Regex.Match(text,"(?<=,).*?(?=\s[A-Z]+\s\d+$)").Value

Regards,

Hi @Ritesh_R

Below is the regex which will give the output in Groups :-

regex101: build, test, and debug regex

Output :-

image

Workflow for the same is below :-
MainPratik.xaml (8.0 KB)

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

@Ritesh_R According to your Higlighted value, you may as well use this Regex in the link below. But please check it for all possible cases as I am considering the City name will be always two letters as such, Depending on your feedback. We’ll modify the regex.

[A-Z]+\s\d+$* Worked, Thanks everyone letting me understand basics

1 Like

[A-Z]+\s\d+$* Worked, Thanks for letting me know basics

1 Like

Hey Ritesh

If you want to learn Regex check out my Regex MegaPost

@cpatras

How to Get Start Numeric Only,
as per above image,
2055
101
830

Hi @Ritesh_R

Below is the regex for the same :-

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

@Pratik_Wavhal

reg1
not work at my place

Also I will be thankful, if you share all expression characters with their usage. Thanks

Hi @Ritesh_R

Can you send all the input text you are using :-

Like this image

And for all expression characters with their usage you will get from below link :-

And also look at the below thread for learning purpose made by @Steven_McKeering

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

@Pratik_Wavhal
As requested

777 Brockton Avenue, Abington MA 2351
30 Memorial Drive, Avon MA 2322
250 Hartford Avenue, Bellingham MA 2019
700 Oak Street, Brockton MA 2301
66-4 Parkhurst Rd, Chelmsford MA 1824
591 Memorial Dr, Chicopee MA 1020
55 Brooksby Village Way, Danvers MA 1923
137 Teaticket Hwy, East Falmouth MA 2536
42 Fairhaven Commons Way, Fairhaven MA 2719
374 William S Canning Blvd, Fall River MA 2721
121 Worcester Rd, Framingham MA 1701
677 Timpany Blvd, Gardner MA 1440
337 Russell St, Hadley MA 1035
295 Plymouth Street, Halifax MA 2338
1775 Washington St, Hanover MA 2339
280 Washington Street, Hudson MA 1749
20 Soojian Dr, Leicester MA 1524
11 Jungle Road, Leominster MA 1453
301 Massachusetts Ave, Lunenburg MA 1462
780 Lynnway, Lynn MA 1905
70 Pleasant Valley Street, Methuen MA 1844
830 Curran Memorial Hwy, North Adams MA 1247
1470 S Washington St, North Attleboro MA 2760
506 State Road, North Dartmouth MA 2747
742 Main Street, North Oxford MA 1537
72 Main St, North Reading MA 1864
200 Otis Street, Northborough MA 1532
180 North King Street, Northhampton MA 1060
555 East Main St, Orange MA 1364
555 Hubbard Ave-Suite 12, Pittsfield MA 1201
300 Colony Place, Plymouth MA 2360
301 Falls Blvd, Quincy MA 2169
36 Paramount Drive, Raynham MA 2767
450 Highland Ave, Salem MA 1970
1180 Fall River Avenue, Seekonk MA 2771
1105 Boston Road, Springfield MA 1119
100 Charlton Road, Sturbridge MA 1566
262 Swansea Mall Dr, Swansea MA 2777
333 Main Street, Tewksbury MA 1876
550 Providence Hwy, Walpole MA 2081
352 Palmer Road, Ware MA 1082
3005 Cranberry Hwy Rt 6 28, Wareham MA 2538
250 Rt 59, Airmont NY 10901
141 Washington Ave Extension, Albany NY 12205
13858 Rt 31 W, Albion NY 14411
2055 Niagara Falls Blvd, Amherst NY 14228
101 Sanford Farm Shpg Center, Amsterdam NY 12010
297 Grant Avenue, Auburn NY 13021
4133 Veterans Memorial Drive, Batavia NY 14020
6265 Brockport Spencerport Rd, Brockport NY 14420
5399 W Genesse St, Camillus NY 13031
3191 County rd 10, Canandaigua NY 14424

Hi @Ritesh_R

It will not show in Regex Builder but while running it will extract the numbers correctly :-

image

Output :-


image

I am attaching the workflow below for the same :-
MainPratik.xaml (10.4 KB)

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

@Pratik_Wavhal
Where I entered regex [1]+ then also its highlighting first row numeric,not all row…
its same as per my prev screen shot. ( IN MY Xaml file)

but it works when I run your file directly …

Did any changes required to strings ???


  1. \d- ↩︎

Hi @Ritesh_R

No changes are required

Actually in my Xaml also it is showing same like yours but when we run the workflow it matches the pattern with each every line at the time of run.

So thats why it can fetch all the Initial numbers as i shown in my output

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer: