developer234
developer234

Reputation: 79

Regular Expression Find Tag within another tag

I want to find all br tags inside of table tag using regular expressions. This is what I have so far:

<table[^>]*>(((<br/>)(?!</table>)).)*</table>

But this code doesn't work in notepad++.

This is what am testing the regular expression with:

<table>
</table>
<table>
<br/>
</table>

Basically the last 3 lines should be found with the regular expressions but the one regular expression I listed above doesn't find anything.

Upvotes: 2

Views: 3329

Answers (1)

Aran-Fey
Aran-Fey

Reputation: 43166

Try

<table(?: [^<>]+)?>(?:(?!</table>).)*<br/>.*?</table>

with dot-matches-all modifier s.

Demo.

Explanation:

<table # start with an opening <table> tag
(?: [^<>]+)?
>
(?: # then, while...
    (?! #...there's no </table> closing tag here...
        </table>
    )
    . #...consume the next character
)*
<br/> # up to the first <br/>
.*? # once we've found a <br/> tag, simply match anything...
</table> #...up to the next closing </table> tag.

Upvotes: 5

Related Questions