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

Posted on 2007-07-29
Last Modified: 2012-06-27
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:


Question by:vishal23
    1 Comment
    LVL 84

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now