I need a regex to match a word that is not in a group of words. I have googled and Stacked question an found some suggestions. But they all were about matching a group of chars, not words. so I tried to write a regex by myself. But I couldn't find a correct regex. Here is my last one that I have tried until now:
(?:(?!office|blog).)+
my words are office, and article. I want input words that are not in this group. Can you help me please?
I think that your Regex should look like this:
Regex r = new Regex(@"\b(?!office|blog|article)\w+\b");
MatchCollection words = r.Matches("The office is closed, please visit our blog");
foreach(Match word in words)
{
string legalWord = word.Groups[0].Value;
...
}
This will return "The", "is", "closed", "please", "visit" and "our".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With