www.example.com/a-292-some-text-here // 292 www.example.com/a-2-asdfss // 2 www.example.com/a-44-333 // 44 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! }