0

I want a regular expression to find all the tr tags that do not contain td

<tr asdf>
<td>
<hello>
</td>
</tr>
<tr asdf>
</tr>

I only want the bottom 2 lines in the code to be found. Here is the template of the regular expression:

<tr.*?>(Cannot figure this section out)</tr>
developer234
  • 79
  • 3
  • 14

2 Answers2

2

You can use this kind of pattern:

<tr[^>]*>(?>[^<]+|<(?!td\b|/tr>))*</tr>

Pattern description:

<tr[^>]*>          # a tr tag with whatever you want inside
(?>                # open an atomic group (like a non-capturing
                   # group but forbids backtracking once it is closed)
    [^<]+          # all that is not a <
  |                # OR
    <(?!td\b|/tr>) # a < not followed by td or /tr>
)*                 # zero or more times
</tr>

or this one (slower, most of the time):

(?s)<tr[^>]*>(?:(?!<td\b).)*?</tr>
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
0
<tr[^>]*>((?!<\/tr>|<td>|<\/td>).)*<\/tr>

Try this.Set g and s flag.See demo.

http://regex101.com/r/uH3tP3/12

vks
  • 67,027
  • 10
  • 91
  • 124