using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var texts = new List { "Shell", "ShellView", "Console", "ConsoleView" }; var rx = new Regex(@"^(\w+?)(View)?$"); foreach (var text in texts) { var match = rx.Match(text)?.Groups[1].Value; Console.WriteLine(match); } } }