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