I am making a regex expression in which I only want to match wrong tags like: *some text here, some other tags may be here as well but no ending \'p\' tag* &
All of the solutions offered so far match the second
, but that's wrong. What if there are two consecutive
elements without closing tags? The second one won't be matched because the first match ate its opening tag. You can avoid that problem by using a lookahead as I did here:
@"(?:[^<]+|<(?!/?p>))*)(?=
As for the rest of it, I used a "not the initial or not the rest" technique along with an atomic group to guide the regex to a match as efficiently as possible (and, more importantly, to fail as quickly as possible if it's going to).