idleberg
idleberg

Reputation: 12872

Sublime Text RegEx pattern for text between HTML tags

I'm using Sublime Text for some search&replace operations. This is an example I'm trying to replace

<blockquote><pre><font face="verdana,arial,helvetica" size="1">code:</font><hr><font size="3">
    <h1>Stuff</h1>
    <p>More stuff and a <a href="#">link</a></p>
    <!-- and any HTML really -->
</font><hr></pre></blockquote>

to look like this

<blockquote>
    <h1>Stuff</h1>
    <p>More stuff and a <a href="#">link</a></p>
    <!-- and any HTML really -->
</blockquote>

The following pattern works as long the HTML inside the blockquote is single line only.

Search:

<blockquote><pre><font face="verdana,arial,helvetica" size="1">code:</font><hr><font size="3">(.*?)</font><hr></pre></blockquote>

Replace:

<blockquote>$1</blockquote>

How can I make this work for multiple lines within the blockquote?

Edit: I came across <tag>([\s\S]*?)</tag> as well, but that includes the opening/closing tag

Upvotes: 3

Views: 8187

Answers (2)

mattsches
mattsches

Reputation: 593

Please try this: <([/]*(font|pre|hr)+)\s*[^>]*>([code:])*

Upvotes: 1

idleberg
idleberg

Reputation: 12872

I ended up using (?:<tag>)([\s\S]+?)(?:</tag>), but I'm sure there's a more efficient way to achieve the same

Upvotes: 12

Related Questions