Derin
Derin

Reputation: 135

Regex to match specific words - C#

I'm looking for a Regex(C#) to match the words "ass" or "a**". That is if the input text contains the word "ass" or "a**" the regex should match. Kindly help me with this.

Thanks in advance.

Upvotes: 0

Views: 1820

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336078

Regex.Match(@"\ba(?:ss\b|\*\*)", RegexOptions.IgnoreCase)

The \b word boundary anchors ensure that you won't accidentally match on assorted or bass.

Upvotes: 7

Related Questions