using System; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { string str = "ghjghjx12klkl122klkl1x33kl0k0l789x2xx6"; // ^^^ ^^^ ^^ ^^ Match match = Regex.Match(str, @"^(?:x(\d+)|\w)+$"); foreach (Capture x in match.Groups[1].Captures) Console.WriteLine(x.Value); } }