<?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[Need help with regex for XML removal]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I’m trying to find a regex that would allow me to remove all XML instances on &lt;machine …&gt; … &lt;/machine&gt; that contain &lt;control type=“gambling” … /&gt;.<br />
Here’s the text I have:</p>
<pre><code>&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;control type="gambling" buttons="21"/&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;
</code></pre>
<p dir="auto">Basically I just want to remove all instances of &lt;machine …&gt;&lt;/machine&gt; if they contain type=“gambling”.</p>
<p dir="auto">Here’s what I have tried but for some reason it does not work:</p>
<pre><code>Find What = (?s)&lt;(machine)\x20((?!&lt;\1).)+?type="gambling".+?&lt;/\1&gt;
Replace With = LEFT EMPTY
Search Mode = REGULAR EXPRESSION
Dot Matches Newline = NOT CHECKED
</code></pre>
<p dir="auto">The weird part is sometimes I manage to find 1 instance (out of thousands) while sometimes it fails completely. Any help will be greatly appreciated.</p>
<p dir="auto">Kind Regards,<br />
Piotr</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/25108/need-help-with-regex-for-xml-removal</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 05:17:28 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/25108.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Nov 2023 17:21:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Need help with regex for XML removal on Wed, 08 Nov 2023 12:10:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> :</p>
<p dir="auto">Interesting.  I hadn’t thought of it as any sort of “general” solution to a problem!</p>
<p dir="auto">[ <em>But, really, there already was the makings of a general solution to half of the problem, from you (ref. <a href="https://community.notepad-plus-plus.org/topic/24716">HERE</a>)</em> ]</p>
<p dir="auto">A couple of notes:</p>
<hr />
<p dir="auto">Note 1:</p>
<blockquote>
<p dir="auto">IF RR = ?1$0:, the complete BSR…ESR sections, WITHOUT the FR string, are deleted</p>
</blockquote>
<p dir="auto">In this variant of the replace expression, the <code>:</code> isn’t necessary, thus:</p>
<p dir="auto">IF <strong>RR</strong> = <code>?1$0</code>, the complete…</p>
<hr />
<p dir="auto">Note 2:</p>
<p dir="auto">Since the overall regex uses group1, it isn’t available in the <strong>BSR</strong>, <strong>ESR</strong>, <strong>FR</strong> and even the <strong>RR</strong> subexpressions.</p>
<p dir="auto">Thus a user of this would have to keep in mind that if he is using further grouping inside these expressions, that he has to think in terms of group2 and above.</p>
<p dir="auto">This is definitely unlike another templated regex solution I use a lot, ref. <a href="https://community.notepad-plus-plus.org/topic/22690">HERE</a>, where the user does not have to keep this in mind.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/90336</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90336</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 08 Nov 2023 12:10:46 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Wed, 08 Nov 2023 05:41:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> Before we get too excited about any of our proposed solutions, I hope we hear more from <a class="plugin-mentions-user plugin-mentions-a" href="/user/piotr-stefa%C5%84ski" aria-label="Profile: Piotr-Stefański">@<bdi>Piotr-Stefański</bdi></a>, the original poster.</p>
<p dir="auto">When I tried copying his example data, duplicating and creating a variant with a different control type, and then making many copies of each all in one file, his original regular expression worked.</p>
<p dir="auto">Unless he reports back to us that one or more of our proposed solutions worked on his actual data, or unless someone else manages to construct an example on which his expression fails and one or more of our solutions works, we don’t know that we have solved anything.</p>
<p dir="auto">We don’t even know what the original problem was. I’m guessing the “complexity” message, which for some reason seems to be cropping up a lot lately; but he has not confirmed that.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/90335</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90335</guid><dc:creator><![CDATA[Coises]]></dc:creator><pubDate>Wed, 08 Nov 2023 05:41:59 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Wed, 08 Nov 2023 08:35:54 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <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/piotr-stefa%C5%84ski" aria-label="Profile: piotr-stefański">@<bdi>piotr-stefański</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: coises">@<bdi>coises</bdi></a> and <strong>All</strong>,</p>
<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>, I’m rather disappointed that you thought I’d <strong>intentionally</strong> omitted to comment on <strong>your</strong> solution :-(</p>
<p dir="auto">As, at this stage, <a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: coises">@<bdi>coises</bdi></a> had found a solution that used <strong>control verbs</strong>, and, what’s more, you had given him a <strong>glowing</strong> review, I just focused on <strong>his</strong> solution !</p>
<p dir="auto">No, I <strong>simply</strong> didn’t notice your response. <strong>Sorry</strong> for this “faux pas” !</p>
<hr />
<p dir="auto">So, allow me to use the <strong><code>Free spacing</code></strong> mode again ! Thus, your regex S/R can be expressed as :</p>
<pre><code class="language-diff">SEARCH  :   (?xs-i) &lt;machine .+? (?: ( type="gambling" .+? &lt;/machine&gt; \R ) | &lt;/machine&gt; \R )
                                       ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
                                                   Group 1

REPLACE :   ?1:$0
</code></pre>
<p dir="auto">And, indeed, you’ve found out a very <strong>powerful</strong> solution, because, if we use in <strong>replacement</strong>, the regex <strong><code>?1$0:</code></strong>, it also <strong>inverts</strong> the logic and <strong>delete</strong> <em>ONLY</em> the sections which do <strong>not</strong> contain the <strong><code>type= "gambling"</code></strong> string !</p>
<hr />
<p dir="auto">So, if we assume that :</p>
<ul>
<li>
<p dir="auto"><strong>BSR</strong> = <strong><code>&lt;machine(?:\x20|&gt;)</code></strong></p>
</li>
<li>
<p dir="auto"><strong>ESR</strong> = <strong><code>&lt;/machine&gt;\R</code></strong></p>
</li>
<li>
<p dir="auto"><strong>FR</strong> = <strong><code>type="gambling"</code></strong></p>
</li>
</ul>
<p dir="auto">This leads to the <strong>generic</strong> regex S/R, below :</p>
<p dir="auto">SEARCH <strong><code>(?s-i)</code>BSR<code>.+?(?:(</code>FR<code>.+?</code>ESR<code>)|</code>ESR<code>)</code></strong></p>
<p dir="auto">REPLACE <strong>RR</strong></p>
<p dir="auto">And :</p>
<ul>
<li>
<p dir="auto">IF <strong>RR</strong> = <strong><code>?1:$0</code></strong>, the complete <strong><code>BSR....ESR</code></strong> sections, <em>WITH</em> the <strong>FR</strong> string, are <strong>deleted</strong></p>
</li>
<li>
<p dir="auto">IF <strong>RR</strong> = <strong><code>?1$0:</code></strong>, the complete <strong><code>BSR....ESR</code></strong> sections, <em>WITHOUT</em> the <strong>FR</strong> string, are <strong>deleted</strong></p>
</li>
</ul>
<hr />
<p dir="auto">Thus, <strong>Alan</strong>, I’m going to add a <strong>new</strong> <em>BLOG</em> post about this <strong>powerful</strong> and simple method, soon ;-))</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/90334</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90334</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Wed, 08 Nov 2023 08:35:54 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Tue, 07 Nov 2023 14:23:00 GMT]]></title><description><![CDATA[<p dir="auto">Thank you everyone, this is a real treasure trove of info.<br />
I’ll experiment with all of the above.</p>
<p dir="auto">Again, huge thanks!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/90328</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90328</guid><dc:creator><![CDATA[Piotr Stefański]]></dc:creator><pubDate>Tue, 07 Nov 2023 14:23:00 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Tue, 07 Nov 2023 14:08:22 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> said in <a href="/post/90317">Need help with regex for XML removal</a>:</p>
<blockquote>
<p dir="auto">Find: <code>(?s-i)&lt;machine.+?(?:(type="gambling".+?&lt;/machine&gt;\R)|(?:&lt;/machine&gt;\R))</code></p>
</blockquote>
<blockquote>
<p dir="auto">Replace: <code>?{1}:$0</code></p>
</blockquote>
<p dir="auto">I feel somewhat <em>slighted</em> as <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> avoided commenting on my proposed solution.  :-(</p>
<p dir="auto">Mine has a bit of symmetry with:</p>
<blockquote>
<p dir="auto">What_I_don’t_want(*SKIP)(*F)|What_I_want&gt;</p>
</blockquote>
<p dir="auto">because I also used an <code>|</code> to specify non-wanted vs. wanted sections.</p>
<p dir="auto">If a non-wanted section (according to the OP’s definition of what he doesn’t want) appears, I captured it into group1 and then my replacement replaces that whole &lt;machine&gt;…&lt;/machine&gt; section with nothing (because there is nothing between the <code>}</code>  and the <code>:</code>), otherwise it replaces that section with itself via <code>$0</code> (thus, keeping it).</p>
]]></description><link>https://community.notepad-plus-plus.org/post/90327</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90327</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 07 Nov 2023 14:08:22 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Tue, 07 Nov 2023 02:21:22 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/piotr-stefa%C5%84ski" aria-label="Profile: piotr-stefański">@<bdi>piotr-stefański</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/coises" aria-label="Profile: coises">@<bdi>coises</bdi></a> and <strong>All</strong>,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/piotr-stefa%C5%84ski" aria-label="Profile: piotr-stefański">@<bdi>piotr-stefański</bdi></a>, instead of the regex <strong><code>(?s)&lt;(machine)\x20((?!&lt;\1).)+?type="gambling".+?&lt;/\1&gt;</code></strong>, use <strong>preferably</strong> this one, below :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s)&lt;machine\x20(?:(?!&lt;machine).)+?type="gambling".+?&lt;/machine&gt;</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
<p dir="auto">This <strong>new</strong> version does <strong>not</strong> use any group to be <strong>stored</strong> ! May be, you’ll get <strong>better</strong> results ;-))</p>
<hr />
<p dir="auto">Now, let’s start, for example, with this¨<em>INPUT</em> text :</p>
<pre><code class="language-xml">&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;

&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;control type="gambling" buttons="21"/&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;

&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;control type="other" buttons="21"/&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;

&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;control type="gambling" buttons="21"/&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;
</code></pre>
<p dir="auto">with the <a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: coises">@<bdi>coises</bdi></a> method, we use its <strong>first</strong> regex S/R :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s)&lt;control type="gambling".*?&lt;/machine&gt;</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>&lt;/machine DELETE&gt;</code></strong></p>
</li>
</ul>
<p dir="auto">To get the <strong>temporary</strong> text below :</p>
<pre><code class="language-xml">&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;

&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;/machine DELETE&gt;

&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;control type="other" buttons="21"/&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;

&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;/machine DELETE&gt;
</code></pre>
<p dir="auto">Then, with its <strong>second</strong> regex S/R :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s)&lt;machine .*?&lt;/machine(*SKIP) DELETE&gt;\R</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
<p dir="auto">We end up with our <strong>expected</strong> <em>OUTPUT</em> text :</p>
<pre><code class="language-xml">&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;


&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;control type="other" buttons="21"/&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;

</code></pre>
<p dir="auto">However, note that its <strong>second</strong> regex S/R could also have been solved without any <strong>control verb</strong>, with the following S/R :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s)&lt;machine (?:(?!&lt;/machine).)*?&lt;/machine DELETE&gt;\R</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
<p dir="auto"><strong>REMARK</strong> :</p>
<p dir="auto">See the <strong>fundamental</strong> difference between these <strong>two</strong> regex S/R syntaxes :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s)&lt;machine .*?&lt;/machine(*SKIP) DELETE&gt;\R</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
<p dir="auto">and</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s)&lt;machine .*?&lt;/machine\K DELETE&gt;\R</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
<p dir="auto">In the <strong>first</strong> case :</p>
<ul>
<li>
<p dir="auto"><em>IF</em> the <strong><code>\x20DELETE\R</code></strong> string is found, all this <strong>specific</strong> section will be <strong>deleted</strong></p>
</li>
<li>
<p dir="auto"><em>IF</em> the <strong><code>\x20DELETE\R</code></strong> string is <em>NOT</em> found, as the <strong>back-tracking</strong> process cannot occur, all this <strong>specific</strong> section is just <strong>ignored</strong></p>
</li>
</ul>
<p dir="auto">But, in the <strong>second</strong> case :</p>
<ul>
<li>
<p dir="auto"><em>IF</em> the <strong><code>\x20DELETE\R</code></strong> string is found, <strong>only</strong> the part <strong><code>\x20DELETE\R</code></strong> will be <strong>deleted</strong>, due to the <strong><code>\K</code></strong> syntax</p>
</li>
<li>
<p dir="auto"><em>IF</em> the <strong><code>\x20DELETE\R</code></strong> string is <em>NOT</em> found, <em>NO</em> replacement  occurs, due to the <strong><code>\K</code></strong> syntax</p>
</li>
</ul>
<hr />
<p dir="auto">Now, a <strong>third</strong> alternative would be to simply use the <strong>generic</strong> regex <strong><code>&lt;What I don't want&gt;(*SKIP)(*F)|&lt;What I want&gt;</code></strong>. Indeed :</p>
<ul>
<li>
<p dir="auto">We do <em>NOT</em> want <strong>all</strong> the <strong><code>&lt;machine .......&lt;/machine&gt;</code></strong> sections, which do <strong>not</strong> contain the <strong><code>type="gambling"</code></strong> string, thus <strong>ignored</strong> sections</p>
</li>
<li>
<p dir="auto">We <em>DO</em> want <strong>all</strong> the <strong><code>&lt;machine .......&lt;/machine&gt;</code></strong> sections, which contain the <strong><code>type="gambling"</code></strong> string, in order to <strong>delete</strong> these <strong>specific</strong> sections by the S/R</p>
</li>
</ul>
<p dir="auto">This leads to the <strong>functional</strong> regex S/R :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?s)&lt;machine (?:(?!type="gambling").)+?&lt;/machine&gt;(*SKIP)(*F)|&lt;machine .+?&lt;/machine&gt;</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
</li>
</ul>
<p dir="auto">And, starting with the <em>INPUT</em> text again, we would obtain, once more, our <strong>expected</strong> <em>OUTPUT</em> :</p>
<pre><code class="language-xml">&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;



&lt;machine name="3bagflnz" sourcefile="aristocrat/aristmk4.cpp" cloneof="3bagflvt" romof="3bagflvt" sampleof="3bagflvt"&gt;
	&lt;description&gt;3 Bags Full (3VXFC5345, New Zealand)&lt;/description&gt;
	&lt;year&gt;1996&lt;/year&gt;
	&lt;manufacturer&gt;Aristocrat&lt;/manufacturer&gt;
	&lt;rom name="2vas004.u59" merge="2vas004.u59" size="8192" crc="84226547" sha1="df9c2c01a7ac4d930c06a8c4863853ddb1a2adbe" region="maincpu" offset="2000"/&gt;
	&lt;device_ref name="mc6809e"/&gt;
	&lt;sample name="tick"/&gt;
	&lt;input players="1" coins="2"&gt;
		&lt;control type="other" buttons="21"/&gt;
	&lt;/input&gt;
	&lt;driver status="good" emulation="good" savestate="unsupported"/&gt;
&lt;/machine&gt;


</code></pre>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/90324</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90324</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 07 Nov 2023 02:21:22 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Mon, 06 Nov 2023 20:15:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/coises" aria-label="Profile: Coises">@<bdi>Coises</bdi></a> said in <a href="/post/90319">Need help with regex for XML removal</a>:</p>
<blockquote>
<p dir="auto">I’d break it into a couple of steps instead of trying to write a single, very clever regular expression.</p>
</blockquote>
<p dir="auto">Ha, yea.  The use of <code>(*SKIP)</code> pretty much makes it just as clever.  :-)</p>
<p dir="auto">Referencing <a href="https://community.notepad-plus-plus.org/post/55465">HERE</a> we have a good explanation:</p>
<p dir="auto"><em>if at current position in string, the regex engine can match the part before (*SKIP) but cannot match the part after (*SKIP), the regex engine discards any further search and the current match attempt just fails. So the regex engine must advance to the location where the zero-width (*SKIP) verb occurs, for a new match attempt</em></p>
]]></description><link>https://community.notepad-plus-plus.org/post/90323</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90323</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 06 Nov 2023 20:15:34 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Mon, 06 Nov 2023 18:45:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/piotr-stefa%C5%84ski" aria-label="Profile: Piotr-Stefański">@<bdi>Piotr-Stefański</bdi></a> said in <a href="/post/90316">Need help with regex for XML removal</a>:</p>
<blockquote>
<p dir="auto">I’m trying to find a regex that would allow me to remove all XML instances on &lt;machine …&gt; … &lt;/machine&gt; that contain &lt;control type=“gambling” … /&gt;.</p>
</blockquote>
<p dir="auto">For what it’s worth:</p>
<p dir="auto">If I were trying to solve this problem for myself, I’d break it into a couple of steps instead of trying to write a single, very clever regular expression.</p>
<p dir="auto">If it is safe to assume that <strong>&lt;control type=“gambling”</strong> never occurs outside of a <strong>&lt;machine</strong> …<strong>&gt;</strong>…<strong>&lt;/machine&gt;</strong> pair, then I would first do:</p>
<p dir="auto"><strong>Find what : <code>&lt;control type="gambling".*?&lt;/machine&gt;</code></strong><br />
<strong>Replace with : <code>&lt;/machine DELETE&gt;</code></strong><br />
<strong>Search Mode: Regular expression</strong><br />
<strong>. matches newline: <em>checked</em></strong></p>
<p dir="auto">Then I’d do:</p>
<p dir="auto"><strong>Find what : <code>&lt;machine .*?&lt;/machine(*SKIP) DELETE&gt;\R</code></strong><br />
<strong>Replace with :</strong> <em>(empty)</em><br />
<strong>Search Mode: Regular expression</strong><br />
<strong>. matches newline: <em>checked</em></strong></p>
]]></description><link>https://community.notepad-plus-plus.org/post/90319</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90319</guid><dc:creator><![CDATA[Coises]]></dc:creator><pubDate>Mon, 06 Nov 2023 18:45:31 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Mon, 06 Nov 2023 18:08:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/piotr-stefa%C5%84ski" aria-label="Profile: Piotr-Stefański">@<bdi>Piotr-Stefański</bdi></a> said in <a href="/post/90316">Need help with regex for XML removal</a>:</p>
<blockquote>
<p dir="auto">it fails completely</p>
</blockquote>
<p dir="auto">As in it claims to find nothing, or as in it shows “Invalid regular expression” at the bottom?</p>
<p dir="auto">If the latter, please hover over the three dots to the right of that message and tell us if it says something about the expression being too complex.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/90318</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90318</guid><dc:creator><![CDATA[Coises]]></dc:creator><pubDate>Mon, 06 Nov 2023 18:08:21 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with regex for XML removal on Mon, 06 Nov 2023 18:23:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/piotr-stefa%C5%84ski" aria-label="Profile: Piotr-Stefański">@<bdi>Piotr-Stefański</bdi></a></p>
<p dir="auto">This or something similar has potential to work:</p>
<p dir="auto">Find: <code>(?s-i)&lt;machine.+?(?:(type="gambling".+?&lt;/machine&gt;\R)|(?:&lt;/machine&gt;\R))</code><br />
Replace: <code>?{1}:$0</code></p>
<p dir="auto">Or maybe it’s just a variant on yours that will still cause complexity too much for the regex engine.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/90317</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/90317</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 06 Nov 2023 18:23:06 GMT</pubDate></item></channel></rss>