Hi all. I have a simple problem: I want to construct a regex that matches a form in HTML, but only if the form has any input tags. Example:
The following should be matched (ignoring attributes):
..
<form>
..
<input/>
..
</form>
..
But the following should not (ignoring attributes):
..
<form>
..
</form>
..
I have tried everything from look-arounds to capture groups but it quickly gets complicated. I want to believe there is a simple regex to capture the problem. Please note that it is important that the regex pairs the opening and closing tags according to the HTML code which means the following does not work:
<form>.+<input/>.+</form>
because it matches wrongly like this:
..
<form> <--- This is wrongly matched as the opening tag
..
</form>
<form> <-- This is the correct opening tag of the correct form
..
<input/>
..
</form> <--- This is matched as the closing tag
..
EDIT:
I already made a RegEx that matches what I want; my question is now how to do it, but how to do it SIMPLE/elegantly. To me this is not simple or elegant at all:
<form>
(.(?<!</form>))+
<input/>
(.(?<!</form>))+
</form>