0

I'm trying to come up with a regex that will split out a string in 3 different parts: Name, Address, and Phone Number.

This is what I currently have:

^(?<Name>\w.*)\s+(?<Address>\d+\s\w+.*\d{5,9})\s+(?<Phone>\d+.*)

Here is what regex101 is giving me back with the following sample string: enter image description here

But if I add in a '#' before the suite number, it works as planned: enter image description here

I've even tried running just the address regex against the entire string in a separate instance and it worked just fine. There's something going on with the capture groups that's throwing it off. Any suggestions would be greatly appreciated!

2
  • 1
    Please provide sample inputs and expected outputs. Not all of our proxies allow us to get to Imgur. Commented Mar 29, 2017 at 22:10
  • Google the US Postal address reader/scanner for the thousands of different format's of addresses. Looks like it's a loosing battle.. Commented Mar 30, 2017 at 0:51

1 Answer 1

1

Try making the name non-greedy:

^(?<Name>\w.*?)\s+(?<Address>\d+\s\w+.*\d{5,9})\s+(?<Phone>\d+.*)
Sign up to request clarification or add additional context in comments.

1 Comment

That did it! Thank you!

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.