如何使用C#中運行的正則表達式找到字符串中的所有匹配項?C#正則表達式匹配字符串中的多個單詞
我想查找下面的示例字符串中的所有匹配項。 實施例:
inputString: Hello (mail) byebye (time) how are you (mail) how are you (time)
我想從示例匹配(mail)
和(time)
。包括括號(
和)
。
在試圖解決這個問題時,我寫了下面的代碼。
string testString = @"(mail)|(time)";
Regex regx = new Regex(Regex.Escape(testString), RegexOptions.IgnoreCase);
List<string> mactches = regx.Matches(inputString).OfType<Match>().Select(m => m.Value).Distinct().ToList();
foreach (string match in mactches)
{
//Do something
}
是用於邏輯OR
條件管道(|
)?
PERFECT !!!! @FishBasketGordo – Nisho