/// inputStr 需要过滤的字符串
/// lst 关键词集合
public static string FilterSensitiveWord(string inputStr,List<string> lst) { var tempLst = lst; if (!string.IsNullOrEmpty(inputStr)) { foreach (var item in lst) { var sensitiveWord = Regex.Escape(item.Trim()); var regexSesitiveWord = ""; for (int i = 0; i < sensitiveWord.Length; i++) { var ch = sensitiveWord[i]; if (ch == '\\') { i++; regexSesitiveWord += @"\" + sensitiveWord[i]; continue; } regexSesitiveWord += ch + @"\s*?"; } inputStr = Regex.Replace(inputStr, regexSesitiveWord, "", RegexOptions.IgnoreCase); if (inputStr == "") { break; } } } return inputStr; }