1

I have a list of address such as the following:

Find Dabla Inc at 6889 66th Ave, NY, NY 11884-3773. Call them at (888) 292-1655.
Find Walgreen Drug Stores at 6008 87th Ave, NY, NY 17774-4314. Call them at (888) 999-473
Find Silver Star Restaurant at 6941 99th Ave Ste A, NY, NY 88804-2915. Call them at (888) 851-2799.

I am trying to extract the street address, state, city and zip code from this text via Regex.

Currently, I am using the following to match street address:

    (?<=at\s)\d{3,5}\s\S*\s\w*.*(?=,)

However, I see it inlcudes in match NY, instead of stopping after the first comma (it only stops after second comma).. Why is it including first comma if I'm using a positive lookahead?

Thannks

1
  • Java.. i thought it was the same for both.. Commented Jul 17, 2015 at 5:46

1 Answer 1

3
(?<=at\s)\d{3,5}\s\S*\s\w*.*?(?=,)

                            ^^

Make your regex non greedy.

See demo: https://regex101.com/r/fX3oF6/14

Sign up to request clarification or add additional context in comments.

2 Comments

I tried. I got: "Cannot accept an answer in 11 minutes" :) I will wait a little to accept..
@KimClinton you can also use (?<=at\s)\d{3,5}\s+[^,]* a shortened version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.