2

I've been working on my own simple Wikipedia parser in C#. So far I'm not getting very far because of this problem.

I extract the string {e|24} but it could contain any number. All I want to do is simply extract the number from this string.

This is the code I am using currently:

Match num = Regex.Match(exp.Value, "[0-9]*");
Console.WriteLine(num.Value);

However num.Value is blank.

Can someone please explain why this is not working and how I can fix it?

ChrisWue
  • 17,984
  • 4
  • 54
  • 79
Benny33
  • 485
  • 1
  • 6
  • 12
  • This is trivial to test in a tool. I use http://www.radsoftware.com.au/regexdesigner/ which will give you exact results for .NET. – Chuck D Jan 09 '13 at 23:56
  • To further explain why this didn't work, [0-9]* actually matches your string in 6 places: `>24 – JLRishe Jan 10 '13 at 00:51

2 Answers2

6

You would want to use [0-9]+ to ensure at least one number. [0-9]* allows it to be matched 0 times or more, thus getting blanks

CorrugatedAir
  • 779
  • 1
  • 5
  • 15
1

My suggestion, make the regexp: \d+

Works. Simpler. Shorter, uses no groups or ranges.

hjc1710
  • 556
  • 4
  • 16