Link to home
Start Free TrialLog in
Avatar of betocarranza
betocarranza

asked on

.NET Simple Regular Expression

I need a regular expression which will match the following patter


somerandomtext HKS 1234 possiblysomemorerandomtext

From the above string, I would like to get back "HKS 1234". The number 1234 could be any number. There might not always be a space between HKS and the number. Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of betocarranza
betocarranza

ASKER

Hi Fernando,

That works if the input is

blahblah HKS 1234 blahblah

but not if it is

blahblah HKS 1234

or

HKS 1234 blahblah rir

or

HKS 1234

Any ideas?
Thanks!
I got it -

      Dim m As Match = Regex.Match(TestString, "(HKS\s*\d+)")


Thanks for your help :)