[Hi my name is Tom Baker.]
[Hi my name is Jim
Knopf.]
[Hi my name is Ben Hubbard.]
I need a regex for C# / .Net that matches "[Hi my name is {anything but "Ben"}{anything can follow}]"
I looked up all the examples that explain how to exclude a word but they all then DON'T match the regex. I want the exact opposite.
If the other rules of the regex apply but word X is not contained that that's the match.
Additional problem: This regex needs to be a multiline regex.
What I've got so far is this:
(?m)\[Hi my name is (.|\r|\n).*?\]
And instead of the first dot in the (.|\r|\n) I need an expression that basically says "if this section does not contain 'Ben' then that's a match".
EDIT
Sorry, I need to adapt my request in two ways, information I only realized I ommitted when I saw the given answers.
1) When I wrote
I need a regex for C# / .Net that matches "[Hi my name is {anything but "Ben"}{anything can follow}]"
I actually meant
I need a regex for C# / .Net that matches "[Hi my name is {anything can be here}{anything but "Ben" can be here}{anything can be here}]"
2) The Regex itself must contain the rule that it is a multiline regex, that's why the \r\n and/or the (?m) are in my first attempt, for complicated reasons I can't use Multiline option when construction the Regex instance.
Try to envision my problem with another example: Imagine you were trying to find all classes in your C# code that don't implement IDisposable. Anywhere after the class name and the colon comes a number of interfaces and one of them may or may not be IDisposable. The class declaration only ends when the openening { of the actual implementation comes
public class Test : BaseTest, IDisposable, ICloneable { //no match
public class Test : BaseTest
, ICloneable
, IDisposable
{ //no match
public class Test : BaseTest
, ICloneable
{ //match
Something like that is what I'm trying to accomplish.