I try to find string that doesn’t contains the same substring. This is my code:
var regex = new Regex(@"aaa(?!.*aaa).*aaa");
var str1 = @"aaa aaa aaa";
var match = regex.Match(str1); // no
var str1 = @"aaa bbb aaa";
var match = regex.Match(str1); // yes
But this code doesn’t work… What I do wrong?
Thanks!
You want an expression like this:
(?:(?!aaa).)*matches strings that do not containaaa(in whole or part).You could also write it like this: