user2840057
user2840057

Reputation: 13

Match string not containg a certain phrase

I need to find all instances of the word "confidential" in a message except when it is used in the phrase "confidential and proprietary" in which case it is ok and I dont need to pick it up through regex.

Thanks all in advance! -P

Upvotes: 0

Views: 84

Answers (2)

hwnd
hwnd

Reputation: 70732

Using word boundaries \b is also an option here.

\bconfidential\b(?! and proprietary\b)

Upvotes: 1

Fabien Sa
Fabien Sa

Reputation: 9480

You can use negative lookaround (http://www.regular-expressions.info/lookaround.html)

This regex will match: (confidential) (?!and proprietary) if your engine support lookaround.

demo: http://regexr.com?36itq

Upvotes: 2

Related Questions