在 C#
中,我想使用正则表达式匹配以下任何单词:
string keywords = "(shoes|shirt|pants)";
我想在字符串中找到整个单词。 我认为这个 regex
会做到这一点:
if (Regex.Match(content, keywords + "\\s+",
RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
{
//matched
}
但是它会对像 participants
这样的单词返回 true,而我只想匹配整个单词pants
。
如何只匹配这些文字?
, RegexOptions.IgnoreCase)
。 - serge