Home > Blockchain >  Regex pattern only catches first occurrence of US address
Regex pattern only catches first occurrence of US address

Time:08-06

I have a transcribed text where customer and agent talks to each other. I want to match addresses. I have a regex pattern:

\d  (.)?(dr|drive|circle|highway|way|street|st|road|rd|boulevard|blvd|parkway|avenue|ave\b|court|ct|cove\b|crossing|estate|junction|loop|park|\bpike\b|ridge|square|terrace|trail|turnpike|village) .*? \d{4,6}

It catches the address. However, it does not catch second address. How to catch all addresses instead of only first occurrence? The second address is appended to end of the sample text 15620 e glenwood... I provide my pattern and sample text below:

Regex 101

CodePudding user response:

i added to your original regex ( \w )? at the begining to iclude the case where the user says the name of the road

this should do the trick :

\d  (.)?( \w  )?(dr|drive|circle|highway|way|street|st|road|rd|boulevard|blvd|parkway|avenue|ave\b|court|ct|cove\b|crossing|estate|junction|loop|park|\bpike\b|ridge|square|terrace|trail|turnpike|village).*?\d{4,6}

if you have any questions feel free to ask me in the comments and if my comment helped you please consider upvoting or marking it as the answer :)

  • Related