<?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[Find and delete all between and including tag only when certain words are within]]></title><description><![CDATA[<p dir="auto">Hi everyone.</p>
<p dir="auto">Newbie here.</p>
<p dir="auto">I have xml files that contain scrolling lyrics for karaoke songs that we are acquiring from another company.  I’m in need of removing each &lt;pg&gt; tag that contain multiline phrases like:</p>
<p dir="auto">8<br />
BAR<br />
INSTRUMENTAL<br />
BREAK</p>
<p dir="auto">They are always on their own separate page within a &lt;pg&gt; tag. The company told us the common words that appear every time are BAR &amp; BREAK.  This will avoid actual lyrics from being deleted within the remaining page tags (hopefully).  There may be multiple instances of these tags throughout the xml as well.  I need find and delete all of them.</p>
<p dir="auto">I’m able to select the opening &lt;pg and all the code up until the next opening &lt;pg one at a time with this regex in Notepad++:</p>
<p dir="auto">(&lt;pg)(.+?)(?=&lt;pg)</p>
<p dir="auto">Is there a way to add code to locate both words BAR  and BREAK to the above regex and only have those full tags found and deleted (multiple times within a file)?  Then I can switch to Find In Files for a bulk search and replace routine?</p>
<p dir="auto">Below is an example of 3 &lt;pg&gt; tags consecutively.  I need the 2nd complete tag found and deleted, then continue on to delete another full &lt;pg&gt; tag if found until it reaches the end of the file.  (rinse and repeat)</p>
<p dir="auto">I have about 24 files to test with 7000 to follow.  I’m hoping the common denominator of words to select between the &lt;pg&gt; tags are always BAR and BREAK.</p>
<p dir="auto">Thank you so much for any help and advice.</p>
<pre><code>```
</code></pre>
<p dir="auto">&lt;pg id=“lyrics.16” t=“157.09,15.88”&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="I’M " t=“161.28,.24”/&gt;<br />
&lt;lyr s="ON " t=“161.52,.43”/&gt;<br />
&lt;lyr s="MY " t=“161.95,.37”/&gt;<br />
&lt;lyr s="OWN " t=“162.32,1.05”/&gt;<br />
&lt;/ln&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="I’M " t=“164.57,.26”/&gt;<br />
&lt;lyr s="ON " t=“164.83,.42”/&gt;<br />
&lt;lyr s="MY " t=“165.25,.43”/&gt;<br />
&lt;lyr s="OWN " t=“165.68,1.07”/&gt;<br />
&lt;/ln&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="I’M " t=“167.91,.24”/&gt;<br />
&lt;lyr s="ON " t=“168.15,.38”/&gt;<br />
&lt;lyr s="MY " t=“168.53,.42”/&gt;<br />
&lt;lyr s="OWN " t=“168.95,.62”/&gt;<br />
&lt;/ln&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="NO " t=“169.57,.48”/&gt;<br />
&lt;lyr s="NO " t=“170.05,.19”/&gt;<br />
&lt;lyr s="NO " t=“170.24,.41”/&gt;<br />
&lt;lyr s="NO " t=“170.65,.43”/&gt;<br />
&lt;lyr s="NO " t=“171.08,.56”/&gt;<br />
&lt;/ln&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="YEAH " t=“171.64,.23”/&gt;<br />
&lt;lyr s="EH " t=“171.87,.42”/&gt;<br />
&lt;lyr s="YEAH " t=“172.29,.58”/&gt;<br />
&lt;/ln&gt;<br />
&lt;/pg&gt;<br />
<strong>&lt;pg id=“lyrics.17” t=“172.97,7.93”&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="8 " t=“174.16,.21”/&gt;<br />
&lt;lyr s="BAR " t=“174.37,.24”/&gt;<br />
&lt;/ln&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="INSTRUMENTAL " t=“174.61,4.52”/&gt;<br />
&lt;/ln&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="BREAK " t=“179.13,1.67”/&gt;<br />
&lt;/ln&gt;<br />
&lt;/pg&gt;</strong><br />
&lt;pg id=“lyrics.18” t=“180.9,9.72”&gt;<br />
&lt;count c=“pt.1” t=“184.92,1.27” n=“4”/&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="WOAH " t=“186.55,.25”/&gt;<br />
&lt;lyr s="OH " t=“186.8,.39”/&gt;<br />
&lt;lyr s="WOAH " t=“187.19,.41”/&gt;<br />
&lt;/ln&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="I " t=“187.6,.21”/&gt;<br />
&lt;lyr s="CAN’T " t=“187.81,.38”/&gt;<br />
&lt;lyr s="LET " t=“188.19,.28”/&gt;<br />
&lt;lyr s="YOU " t=“188.47,.38”/&gt;<br />
&lt;lyr s="GO " t=“188.85,.6”/&gt;<br />
&lt;/ln&gt;<br />
&lt;ln&gt;<br />
&lt;lyr s="MY " t=“189.45,.44”/&gt;<br />
&lt;lyr s="LITTLE " t=“189.89,.6”/&gt;<br />
&lt;lyr s="GIRL " t=“190.49,.03”/&gt;<br />
&lt;/ln&gt;<br />
&lt;/pg&gt;</p>
<pre><code></code></pre>
]]></description><link>https://community.notepad-plus-plus.org/topic/24323/find-and-delete-all-between-and-including-tag-only-when-certain-words-are-within</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Nov 2026 07:06:02 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/24323.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Apr 2023 15:21:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Find and delete all between and including tag only when certain words are within on Sat, 01 Apr 2023 19:11:02 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/jeff-michaels" aria-label="Profile: jeff-Michaels">@<bdi>jeff-Michaels</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/dinkumoil" aria-label="Profile: dinkumoil">@<bdi>dinkumoil</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Congratulations to <strong>brilliantly</strong> achieve your goal from the <strong>link</strong> provided by <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a> ;-)) You seem to be a regex’s <strong>guru</strong>, too !</p>
<hr />
<p dir="auto">Regarding your solution, I suppose that the <strong>end</strong> should be <strong><code>\r\n</code></strong> ( instead of <strong><code>\r\t</code></strong> )</p>
<p dir="auto">Now, I think that you can <strong>simplify</strong> your regex as :</p>
<p dir="auto"><strong><code>(?xs-i) &lt;pg \x20 (?: (?! &lt;/pg&gt; ) . )*? BAR .*? BREAK .*? &lt;/pg&gt; \R  # Delete any &lt;pg&gt; section containing BAR and BREAK</code></strong></p>
<ul>
<li>
<p dir="auto">Indeed, <strong>no</strong> need to be sure that the string <strong><code>&lt;/pg&gt;</code></strong> does <strong>not</strong> occur between the words <strong><code>BAR</code></strong> and <strong><code>BREAK</code></strong>  and between <strong><code>BREAK</code></strong> and <strong><code>&lt;/pg&gt;</code></strong>. Once you get the <strong>good</strong> <strong><code>&lt;pg...&gt;</code></strong> block, with the <strong>negative</strong> look-ahead, the <strong>lazy</strong> quantifiers, coming next, forces the <strong>correct</strong> detection of that block !</p>
</li>
<li>
<p dir="auto">You may use <strong><code>\R</code></strong> as is stands for <strong>any</strong> kind of <strong>line-break</strong> ( <strong><code>\r\n</code></strong>, <strong><code>\n</code></strong> and <strong><code>\r</code></strong> )</p>
</li>
<li>
<p dir="auto">Note that I use the <strong>Free-spacing</strong> mode ( <strong><code>(?x...</code></strong> ) which allows to <strong>separate</strong> the <strong>main</strong> parts of the regex and allows <strong>comments</strong> after the <strong><code>#</code></strong> char</p>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/85395</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85395</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 01 Apr 2023 19:11:02 GMT</pubDate></item><item><title><![CDATA[Reply to Find and delete all between and including tag only when certain words are within on Sat, 01 Apr 2023 18:21:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeff-michaels" aria-label="Profile: Jeff-Michaels">@<bdi>Jeff-Michaels</bdi></a></p>
<p dir="auto">You could install the <em>XmlTools</em> plugin (available via <em>PluginsAdmin</em>) and use its <code>XSL Transformation</code> feature to resolve your issue.</p>
<p dir="auto">After installing the plugin, save the following for example as <code>DeletePgTag.xsl</code> in character encoding <code>UTF-8</code>:</p>
<pre><code class="language-xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output
    method="xml"
    omit-xml-declaration="no"
    indent="yes"
    encoding="UTF-8"
  /&gt;

  &lt;xsl:template match="@*|node()"&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:apply-templates select="@*|node()"/&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="/root/pg[ln[lyr[@s='8 '] and lyr[@s='BAR ']] and ln/lyr[@s='INSTRUMENTAL '] and ln/lyr[@s='BREAK ']]"&gt;
    &lt;xsl:text&gt;&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:transform&gt;
</code></pre>
<p dir="auto"><strong>Please note:</strong></p>
<ul>
<li>
<p dir="auto">Since you did not tell us what is the exact XML path to your <code>&lt;pg&gt;</code> nodes, I decided to assume it could be <code>root</code>, see the search expression in line 18 <code>&lt;xsl:template match="/root/pg ...</code>. You have to change that to your needs.</p>
</li>
<li>
<p dir="auto">Also, if the encoding of your XML file is not <code>UTF-8</code>, you have to change the <code>encoding</code> attribute of the <code>xsl:output</code> node in line 9 to your needs.</p>
</li>
</ul>
<p dir="auto"><strong>Now:</strong></p>
<ol>
<li>Load your XML file with <em>Notepad++</em>. Ensure that it is  the active tab.</li>
<li>Navigate to <code>(menu) -&gt; Plugins -&gt; XML Tools -&gt; XSL Transformation</code>.</li>
<li>In the dialog popping up select the XSL file you created from the code above.</li>
<li>Click <code>Transform</code> button.</li>
</ol>
<p dir="auto">A new tab will be opened with the changed content of your original XML file.</p>
<p dir="auto">[EDIT]<br />
Uh, too late.<br />
[/EDIT]</p>
]]></description><link>https://community.notepad-plus-plus.org/post/85393</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85393</guid><dc:creator><![CDATA[dinkumoil]]></dc:creator><pubDate>Sat, 01 Apr 2023 18:21:20 GMT</pubDate></item><item><title><![CDATA[Reply to Find and delete all between and including tag only when certain words are within on Sat, 01 Apr 2023 18:04:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> thank you.  With a little work, I was able to create this with the help of the thread you suggested.  It’s a messy solution (just like my question was), but it’s working on the 30 files I tested, plus none of the actual lyrics are removed by mistake.</p>
<pre><code>(?s-i:&lt;pg(?:(?!&lt;/pg&gt;).)*?BAR(?:(?!&lt;/pg&gt;).)*?BREAK(?:(?!&lt;/pg&gt;).)*?&lt;/pg&gt;)\r\t
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/85392</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85392</guid><dc:creator><![CDATA[Jeff Michaels]]></dc:creator><pubDate>Sat, 01 Apr 2023 18:04:56 GMT</pubDate></item><item><title><![CDATA[Reply to Find and delete all between and including tag only when certain words are within on Sat, 01 Apr 2023 15:24:12 GMT]]></title><description><![CDATA[<p dir="auto">I think you might find <a href="https://community.notepad-plus-plus.org/topic/24311">THIS THREAD</a> and its discussion relevant to your problem.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/85390</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85390</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sat, 01 Apr 2023 15:24:12 GMT</pubDate></item></channel></rss>