Reputation: 157
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:
But if I add in a '#' before the suite number, it works as planned:
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!
Upvotes: 0
Views: 88
Reputation: 11489
Try making the name non-greedy:
^(?<Name>\w.*?)\s+(?<Address>\d+\s\w+.*\d{5,9})\s+(?<Phone>\d+.*)
Upvotes: 1