Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2007-07-29
1
Medium Priority
?
399 Views
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: http://regexlib.com/RETester.aspx

Thanks.




0
Comment
Question by:vishal23
1 Comment
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 19590063
(this((?!not).)*good)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
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…
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

569 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