Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression (match word + some number) C#

Tags:

c#

regex

Sorry doing this the fast way of asking all the regex experts out there :)

What regex for C# can I use that matches the end of a word + some number

Eg. End of string matches with "Story" + 0 or more numbers

"ThisIsStory1"    = true
"ThisIsStory2000" = true
"ThisIsStory"     = true
"Story1IsThis"    = false
"IsStoryThis1"    = false

Hope this makes sense

A regular expression that I could plug into C# would be fantastic.

Thanks

like image 981
Jerrold Avatar asked Jul 25 '11 16:07

Jerrold


2 Answers

You'll need something like this Story[0-9]*$

So it matches for story (ignoring anything before it, you may need to add more), then for 0 or more numbers between story and the end of the string.

like image 108
Ray Avatar answered Sep 28 '22 23:09

Ray


Try [A-Za-z]*Story[0-9]*.

If you want to check against a whole line, ^[A-Za-z]*Story[0-9]*$.

like image 20
Cajunluke Avatar answered Sep 28 '22 23:09

Cajunluke