using System; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { char[] separators = { ' ', '.', ',', '!', '?', ':', ';', '(', ')', '\t' }; string[] wordsToDelete = { "Hello", "Thanks", "kinda" }; string SepPattern = new String(separators).Replace(@"\", @"\\").Replace("^", @"\^").Replace("-", @"\-").Replace("]", @"\]"); var pattern = $@"\b(?:{string.Join("|", wordsToDelete.Select(Regex.Escape))})\b[{SepPattern}]*"; Console.WriteLine(pattern); Regex rx = new Regex(pattern, RegexOptions.Compiled); DeleteWordsFromText("Hello, how are you?", rx); DeleteWordsFromText("Thanks, I am kinda. good.", rx); } public static void DeleteWordsFromText(string text, Regex p) { Console.WriteLine($"---- {text} ----"); Console.WriteLine(p.Replace(text, "")); } }