How can I build regex with certain rule

Hey everyone,

I want to build a regex that if the input contains any of the the words “yellow” or “blue” or “red” i want it to return true.

for example input : “sky is blue” i want it to return true.

Hi

Can you try the following?

System.Text.RegularExpressions.Regex.IsMatch(text,"yellow|blue|red")

or

System.Text.RegularExpressions.Regex.IsMatch(text,"yellow|blue|red",System.Text.RegularExpressions.RegexOptions.IgnoreCase)

(If you want to ignore case.)

Regards,

2 Likes