Regex.Match whole words

.net, c#, regex

Solution

You should add the word delimiter to your regex:

\b(shoes|shirt|pants)\b

In code:

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

Problem

In `C#`, I want to use a regular expression to match any of these words: ``` string keywords = "(shoes|shirt|pants)"; ``` I want to find the whole words in the content string. I thought this `regex` would do that: ``` if (Regex.Match(content, keywords + "\\s+", RegexOptions.Singleline | RegexOptions.IgnoreCase).Success) { //matched } ``` 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?

Original source