tags:

views:

33

answers:

1

My url looks like:

www.example.com/a-292-some-text-here  // 292
www.example.com/a-2-asdfss       // 2
www.example.com/a-44-333      // 44

I need a regex to get the 292 from the url.

The ID will always be an integer.

i am using C#.

+2  A: 

Use Regex.Match with @"\d+":

string input = "www.example.com/a-292-some-text-here";
Match match = Regex.Match(input, @"\d+");
if (match.Success)
{
    int id = int.Parse(match.Value);
    // Use the id...
}
else
{
    // Error!
}
Mark Byers
thanks...updated with some more examples.
Blankman
@Blankman: I believe that the code I provided above gives you what you want for each of your example inputs.
Mark Byers