<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to remove all HTML tags except &lt;p&gt; or &lt;h1&gt; &lt;h2&gt; tags?]]></title><description><![CDATA[<p dir="auto">I have several articles in txt files under a directory.</p>
<p dir="auto">The articles’ html code is somehow messed up.</p>
<p dir="auto">I wish to remove all html tags except  &lt;p&gt; or &lt;h1&gt; &lt;h2&gt; tags</p>
<p dir="auto">The following code is removing all HTML tags<br />
&lt;[^&gt;]+&gt;</p>
<p dir="auto">How to add an exception?<br />
Keep any tags that have p, h1 or h2</p>
<p dir="auto">Thank you in advance for your sharing of RegEx knowledge!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/19727/how-to-remove-all-html-tags-except-p-or-h1-h2-tags</link><generator>RSS for Node</generator><lastBuildDate>Sat, 06 Jun 2026 04:11:37 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/19727.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 18 Jul 2020 15:18:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to remove all HTML tags except &lt;p&gt; or &lt;h1&gt; &lt;h2&gt; tags? on Sat, 18 Jul 2020 21:42:51 GMT]]></title><description><![CDATA[<p dir="auto">I found this code will do the job<br />
&lt;/?(?!a)(?!p)(?!ul)(?!li)(?!h)\w*\b[^&gt;]*&gt;</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56047</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56047</guid><dc:creator><![CDATA[NZ Select]]></dc:creator><pubDate>Sat, 18 Jul 2020 21:42:51 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove all HTML tags except &lt;p&gt; or &lt;h1&gt; &lt;h2&gt; tags? on Sat, 18 Jul 2020 20:46:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a></p>
<p dir="auto">Thank you for the reply.</p>
<p dir="auto">This code now replace all html codes except h1,h2,or p tag<br />
&lt;(?!h1|h2|p)[^&gt;]+&gt;</p>
<p dir="auto">But I notice that it also replace the ending &lt;/h1&gt;, &lt;/h2&gt;, and &lt;/p&gt;<br />
I tried to use these below try to keep the above tags, it failed.<br />
&lt;(?!h1|/h2|h2|/h2||p|/p)[^&gt;]+&gt;<br />
or this<br />
&lt;(?!h1|\h2|h2|\h2||p|\p)[^&gt;]+&gt;</p>
<p dir="auto">Would you advise how to keep the trialing tags?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56045</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56045</guid><dc:creator><![CDATA[NZ Select]]></dc:creator><pubDate>Sat, 18 Jul 2020 20:46:12 GMT</pubDate></item><item><title><![CDATA[Reply to How to remove all HTML tags except &lt;p&gt; or &lt;h1&gt; &lt;h2&gt; tags? on Sat, 18 Jul 2020 16:43:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nz-select" aria-label="Profile: NZ-Select">@<bdi>NZ-Select</bdi></a> ,</p>
<p dir="auto">I would recommend a <a href="https://npp-user-manual.org/docs/searching/#assertions" rel="nofollow ugc">negative lookahead assertion</a>: FIND = <code>&lt;(?!h1|h2|p)[^&gt;]+&gt;</code>: that says, “look for &lt;, lookahead and make sure it isn’t h1 or h2 or p, consume one or more non-&gt; characters until the first &gt; found”</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56036</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56036</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Sat, 18 Jul 2020 16:43:29 GMT</pubDate></item></channel></rss>