
If "My" is at the end of the entire string, you'll never match anything because every lookahead will fail because they will all see that.

The first three words fail to match because My happens after them. The reason why lookahead doesn't work is because it fails in this relatively simple case: So after looking through these topics on RegEx's: lookahead, lookbehind, nesting, AND operator, recursion, subroutines, conditionals, anchors, and groups, I've come to the conclusion that there is no solution that satisfies what you're asking for. I'm STILL just wondering if there is a native regex construct that could do this. Where !Regex.IsMatch(m.Value, negativePattern) Return (from Match m in Regex.Matches(input, positivePattern) If there answer is "it does not exist and here is why." I'd like to know that too.Įdit 2: If I wanted to define my own function to do this it would be something like (here's a C# LINQ version): public static Match RegexMNI(string input, So.what about excluding matches that contain "My" somewhere in the middle?.I'm still really looking for a general construct, like a regex equivalent of the following pseudo-sql select from (Bohemian I still gave you an upvote for illustrating this). Like match ((?<=(so|me|^))big(com?plern) except when it starts with "My".Įdit: I realize that was a bad example, since excluding stuff at the begginning or end is a situation where negative look-ahead and look-behind expressions work. But i'm looking for a more general construct so that at least the large positive set can be a more complex expression.

For this little example, sure, I could manually reconstruct something like, which is a pain but doable.

I can't just say because that doesn't take into account the larger limiting set of only word characters. Note I'm subtracting a small set (the letter 'p') from a larger set (all word characters). This is hard to explain both completely and e Material Nonimplication for a formal definition.įor example, match any word character ( \w) EXCEPT 'p'.

I'm looking for a general regex construct to match everything in pattern x EXCEPT matches to pattern y.
