我想要一个正则表达式来查找所有不包含td
的tr标签<tr asdf>
<td>
<hello>
</td>
</tr>
<tr asdf>
</tr>
我只想找到代码中的底部2行。这是正则表达式的模板:
<tr.*?>(Cannot figure this section out)</tr>
答案 0 :(得分:2)
您可以使用这种模式:
<tr[^>]*>(?>[^<]+|<(?!td\b|/tr>))*</tr>
模式描述:
<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>
或者这个(较慢,大部分时间):
(?s)<tr[^>]*>(?:(?!<td\b).)*?</tr>
答案 1 :(得分:0)