Regular Expression that matches a phrase that doesn't contain this word

I need help writing a regular expression in c# that will match a pattern that does not contain a certain subpattern.

My source string: "this is notgood this is good"
What I want it to return/match: this is good
My regex MUST be something like:  this.*good

But right now it will return the whole source string:

So my questions is how do I modify "this.*good" to ignore the part that has NOTGOOD and only return "this is good" ?

I tried this.*[^(notgood)]*good but that doesn't do it. The [^notgood] excludes only single characters not words.

I am testing the regex here: http://regexlib.com/RETester.aspx

Thanks.




vishal23Asked:
Who is Participating?
 
ozoCommented:
(this((?!not).)*good)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.