C# Regular Expression To Match Number at end of a string
c#
Solution
Try this:
(\d+)$
Here is an example of how to use it:
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
Regex regex = new Regex(@"(\d+)$",
RegexOptions.Compiled |
RegexOptions.CultureInvariant);
Match match = regex.Match("_1_12");
if (match.Success)
Console.WriteLine(match.Groups[1].Value);
}
}
Problem
I have a string that ends with _[a number] e.g. _1 _12 etc etc. I'm looking for a regular expression to pull out this number