0
我正在使用正則表達式來獲取任何位置字符串內某個單詞的匹配。我使用正則表達式是C#字符串包含字Regex
^(?=.*\bMaster\b).+$
或
\bMaster\b
手段主字如果字符串來自任何地方,應該匹配。 ,我試圖以匹配C#代碼是
public bool Match(string message)
{
this.match = Regex.Match(message, this.RegexPattern, RegexOptions.IgnoreCase);
return match.Success;
}
但我在任何情況下
case 1: I am Master
Case 2: Master
Case 3: Master you are
只是'\ bMaster \ B'就足夠了。 – 2014-09-30 07:39:14
是使用這個,但不工作,我得到錯誤的錯誤 – user3226440 2014-09-30 07:39:48
什麼@AvinashRaj說;但請注意,C#沒有正則表達式文字,並且您正在從字符串構造正則表達式,因此請確保使用雙反斜槓('「\\ bMaster \\ b」')或使用原始字符串文字('@「\ bMaster \ b「')。 '「\ bMaster \ b」'相當於''bMasterb「',你大概沒有測試過。 – Amadan 2014-09-30 07:40:13