Regex.Match whole words

后端 未结 4 1421
暖寄归人
暖寄归人 2020-11-22 07:58

In C#, I want to use a regular expression to match any of these words:

string keywords = \"(shoes|shirt|pants)\";

I want to fi

4条回答
  •  有刺的猬
    2020-11-22 08:15

    You should add the word delimiter to your regex:

    \b(shoes|shirt|pants)\b
    

    In code:

    Regex.Match(content, @"\b(shoes|shirt|pants)\b");
    

提交回复
热议问题