由网友(年华似水终老去゛)分享简介:在 C#,我想用一个常规的前pression匹配任何字:In C#, I want to use a regular expression to match any of these words:string keywords = "(shoes|shirt|pants)";我想找到整个词语的内容字符串。我认为这正...
在 C#
,我想用一个常规的前pression匹配任何字:
In C#
, I want to use a regular expression to match any of these words:
string keywords = "(shoes|shirt|pants)";
我想找到整个词语的内容字符串。我认为这正则表达式
将做到这一点:
if (Regex.Match(content, keywords + "s+",
RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
{
//matched
}
但像参加
的话返回true,即使我只想要整个单词裤子
。
but it returns true for words like participants
, even though I only want the whole word pants
.
我怎么只匹配那些文字的话?
How do I match only those literal words?
推荐答案
您应该添加单词分隔符的正则表达式:
You should add the word delimiter to your regex:
b(shoes|shirt|pants)b
在code:
Regex.Match(content, @"b(shoes|shirt|pants)b");
相关推荐
最新文章