Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a string
K9908098F, G2342D34324/ 234234323, 234-234-234; R324234
How to catch only 234234323 and 234-234-234 in VBA?
234234323
234-234-234
This [\d-]+ pattern grabs extra pieces
[\d-]+
You are pretty close, just need to add borders: \b[\d-]+\b
\b[\d-]+\b
Regex demo and explanation
Add a comment
Give this a try:
(\w+),\s+([\w-]+);
This will capture 234234323 in group 1 and 234-234-234 in group 2.
Not too elegant though but would work. Just a small addition to your regex.
[\d-]+[,;]
You can try this too,
[-\d]+(?=[;,. ])
Demo
Required, but never shown
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.
Explore related questions
See similar questions with these tags.