1

After many hours of searching I have found a regex that validates the street address (just the street without city/state/zip). This is for US use only. It's been difficult to find any that would fit my needs or that worked with numbered streets.

The one I'm using works great except for instances like

12345 5th ave ne
4367 103rd North
1234 Main St     <- currently works but needs to work after fix
12345 Apple Way  <- currently works but needs to work after fix

all current working instances need to continue to work.

The problem it wants the Ave (or st/etc) at the end and I need to allow all the combinations of north/south/west/east as single or double combinations to be on the end also (ex. SouthWest, NE, NorthEast).

Instead of including each combination I'd like to regex to allow (match) when one of those combinations or a single one is found (case insensitive). I also would like to optimize the Way/Street/etc to also be case insensitive

For my usage, unit #/Apt #/etc will not be used its strictly for the base street address.

This is what I currently have:

\d+[ ](?:[A-Za-z0-9.-]+[ ]?)+(?:Avenue|Lane|Road|Boulevard|Drive|Street|Way|Ave|Dr|Rd|Blvd|Ln|St|Wy|avenue|lane|road|boulevard|drive|street|way|ave|dr|rd|blvd|ln|st|wy)\.?

I appreciate any and all assistance.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
EagleDude
  • 11
  • 1
  • Good luck with street addresses like [RR 3 Box 240-5](https://www.hudsonandmarshall.com/property-details/rr-3-box-240-5-sallisaw-74955-ok-united-states) and [One Infinite Loop](https://en.wikipedia.org/wiki/Apple_Campus) or most of the items on [this list of standard abbreviations for postal street name suffixes](https://pe.usps.com/text/pub28/28apc_002.htm) – Raymond Chen Mar 16 '19 at 17:23
  • Appreciate the call out, but in this use those will not be required, what I have works except as noted, would like to be able to provide a validation of something that looks somewhat close to an address with the types that I have mentioned – EagleDude Mar 16 '19 at 17:44

1 Answers1

0

Try this:

/\d+\s[\w]+\s(.*)/i

You can get the street by calling the group match 1.

DEMO

UPDATE

If you want to get entire 'main street' and 'apple way', you can do it by calling the group match 2 using this regex:

\d+\s(\d*[a-z]+)?\s?(.*)

DEMO

Kevin A.S.
  • 123
  • 7
  • A little too simplistic would like to only validate something that resembles an address matching on "2 b" is too lenient , like I indicated what I had was meeting needs except that it didnt allow for NW, North, etc at the end – EagleDude Mar 16 '19 at 17:18
  • I should probably add that I am using this in a html form pattern= – EagleDude Mar 16 '19 at 17:32
  • Can you give me the original data that you want to match and your expected matches from that data? – Kevin A.S. Mar 16 '19 at 17:53