I need a regular expression to find out whether or not a h1 tag is followed by a h2 tag, without any paragraph elements in between. I tried to use a negative lookahead but it doesn’t work:
<h1(.+?)</h1>(\s|(?!<p))*<h2(.+?)</h2>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
should work.
It matches exactly one
h1tag, then any amount of characters up to the nexth2tag, but only if noptag is found along the way.Since in this scenario it is rather unlikely that nested tags would occur, this should be quite reliable, even with regex.
You’ll need to activate your tool’s/language’s option for the dot to match newline characters. It might be enough to prefix your regex with
(?s)to achieve this.