Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
I don't know much about regex and no-one here is sober enough to help.

I have to search a string:
"ghlkj djfghdf word99999x dfkl;klsdf sdgjkhdfgjk fdsdsfsd"
and find "word99999x"

word - will be a variable length alpha string.
99999 - a five digit number.
x - one of a list of characters - e.g. xyz

Any help how to form this would be much appreciated.
Posted

1 solution

Try
([a-zA-z]+\d{5}[xyz])


Have a look at Expresso[^] - it's free and really helps with regexes!
 
Share this answer
 
Comments
sjelen 23-Dec-10 8:39am    
You have a typo: 'A-z' instead 'A-Z'.
I would add marking of first and last char in word (\b):
(\b[a-zA-Z]+\d{5}[xyz]\b)
Nagy Vilmos 23-Dec-10 8:40am    
Thanks Griff.
Manfred Rudolf Bihy 23-Dec-10 10:07am    
Good call! +5
Good link +5 ... Oh wait, I ran out of voting options :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900