Regex.Match whole words

后端 未结 4 1431
暖寄归人
暖寄归人 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:25

    Try

    Regex.Match(content, @"\b" + keywords + @"\b", RegexOptions.Singleline | RegexOptions.IgnoreCase)
    

    \b matches on word boundaries. See here for more details.

提交回复
热议问题