I am working on a site that is using the unfortunate practice of wrapping <tr/> tags inside of <form/> tags for the purpose of being able to submit the contents of single rows as form posts to the server. The HTML is generated via XSL, and sometimes there is XSL flow control (<xsl:if/>, <xsl:choose/>, etc.) or <xsl:attribute/> tags between the <form/> and <tr/> tags.
Example:
<table>
<tbody>
<form id="row1_form">
<xsl:if test="test">
<xsl:attribute name="foo">bar</xsl:attribute>
</xsl:if>
<tr id="row1">
...
I am trying to write an regex that will find all the places that a “<tr” string occurs at some point after a “<form” string. The following works for this:
<form[^<]*?>[\s\w\<\:\>\/]*<tr
What I really need, though, is for the above regex to only match when the string “<table” does NOT occur between the “<form” and “<tr” strings. If the string “<table” does not occur between “<form” and “<tr“, then I know that I have found an invalid placement of a form tag.
Thanks,
Matt
If your regular expression engine supports negative lookarounds you can do: