I can’t find how to exclude a string in my regex :
ex :
<div\s[^>]+>
will find a <div and every characters before its closing >
Now I would like to find the <div...> then everything but a </div> then a </div>. Something like :
<div\s[^>]+>[^(</div>)]*</div>
The problem is [^abc] is excluding a or b or c. How can I exclude the “abc” string?
That’s what negative lookahead assertions are for:
Explanation:
You might want to make the slash optional (
(?!</?div>)); otherwise you would trip up on nested tags like in<div> foo <div> bar </div> baz </div>.