<?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 empty spaces from a particular tag (regular expression)]]></title><description><![CDATA[<p dir="auto">good day, I made this regular expression to remove empty spaces from a particular tag that has many empty spaces and tabs:</p>
<p dir="auto"><code>(?-s)(\G(?!^)|&lt;p\s+class="oyric"&gt;)((?!&lt;/p&gt;).)*?\K\s\s+</code>   but it does not work well</p>
<pre><code>&lt;p class="oyric"&gt;  Laurie Strode comes to   her final confrontation		 with Michael Myers, the   masked figure  who has haunted her 	  since she narrowly escaped.  &lt;/p&gt;
</code></pre>
<p dir="auto">Output should be:</p>
<pre><code>&lt;p class="oyric"&gt;Laurie Strode comes to her final confrontation with Michael Myers, the masked figure who has haunted her since she narrowly escaped.&lt;/p&gt;
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/topic/16533/how-to-remove-empty-spaces-from-a-particular-tag-regular-expression</link><generator>RSS for Node</generator><lastBuildDate>Mon, 15 Jun 2026 20:19:40 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/16533.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Oct 2018 07:34:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to how to remove empty spaces from a particular tag (regular expression) on Sat, 29 Dec 2018 09:41:23 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>  I just review this post, because I like it and remembered the same thing from the post today.</p>
<p dir="auto">SEARCH <code>(?s)(?:\G|&lt;p class="oyric"&gt;)(?:(?!&lt;|&gt;).)*?\K(?:(^\h+)|\h+$|(?&lt;=&gt;)\h+|\h+(?=&lt;/p&gt;)|(\h{2,})(?=[^&lt;\h]))</code></p>
<p dir="auto">REPLACE <code>(?1$0)(?2\x20)</code></p>
<p dir="auto">What if, in case I have another tag, like <code>&lt;em&gt;</code></p>
<p dir="auto">So, @Robin Cruise scenario become:</p>
<p dir="auto"><code>&lt;p class="oyric"&gt;  Laurie Strode comes to   her final confrontation    &lt;em&gt;  with Michael Myers, the   masked figure  who has haunted her     &lt;/em&gt;since she narrowly escaped.  &lt;/p&gt;</code></p>
<p dir="auto">So, In this case, your regex does not remove empty spaces because of those <code>&lt;em&gt;</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/37851</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/37851</guid><dc:creator><![CDATA[Neculai I. Fantanaru]]></dc:creator><pubDate>Sat, 29 Dec 2018 09:41:23 GMT</pubDate></item><item><title><![CDATA[Reply to how to remove empty spaces from a particular tag (regular expression) on Mon, 03 Dec 2018 13:41:07 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> said:</p>
<blockquote>
<p dir="auto">(?1$0)(?2\x20)</p>
</blockquote>
<p dir="auto">also, it can be replace with: <code>(?{2}$1 )</code> such as:</p>
<p dir="auto">SEARCH: <code>(?:(^\h+)|\h+$|(?&lt;=&gt;)\h+|\h+(?=&lt;/p&gt;)|(\h{2,})(?=[^&lt;\h]))</code></p>
<p dir="auto">REPLACE BY: <code>(?{2}$1 )</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/37102</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/37102</guid><dc:creator><![CDATA[Neculai I. Fantanaru]]></dc:creator><pubDate>Mon, 03 Dec 2018 13:41:07 GMT</pubDate></item><item><title><![CDATA[Reply to how to remove empty spaces from a particular tag (regular expression) on Sat, 10 Nov 2018 17:53:11 GMT]]></title><description><![CDATA[<p dir="auto">well done, thank you very much</p>
]]></description><link>https://community.notepad-plus-plus.org/post/36207</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/36207</guid><dc:creator><![CDATA[Robin Cruise]]></dc:creator><pubDate>Sat, 10 Nov 2018 17:53:11 GMT</pubDate></item><item><title><![CDATA[Reply to how to remove empty spaces from a particular tag (regular expression) on Sun, 11 Nov 2018 12:34:08 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/robin-cruise" aria-label="Profile: Robin-cruise">@<bdi>Robin-cruise</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Ah Yes ! My regex wasn’t enough <strong>accurate</strong> ! And <strong>worse</strong>, my <strong>formulation</strong> of the <strong>general</strong> regex solution was <strong>not</strong> exact too :-((</p>
<hr />
<p dir="auto">So, the <strong>general</strong> regex solution, when you want to perform a <strong>Search/Replacement</strong> in a <strong>specific</strong> area, <strong>only</strong>, is :</p>
<p dir="auto">SEARCH <strong><code>(?-s)(\G|</code>BR<code>)((?!</code>ER<code>).)*?\K</code>SR</strong>        OR        <strong><code>(?s)(\G|</code>BR<code>)((?!</code>ER<code>).)*?\K</code>SR</strong></p>
<p dir="auto">REPLACE <strong>RR</strong></p>
<p dir="auto">where :</p>
<ul>
<li>
<p dir="auto"><strong>BR</strong> ( <strong>B</strong>egining <strong>R</strong>egex ) is the regex which defines, either, the <strong>start</strong> of that <strong>specific</strong> area and the <strong>start</strong> for a possible <strong>S</strong>earch <strong>R</strong>egex match</p>
</li>
<li>
<p dir="auto"><strong>ER</strong> ( <strong>E</strong>xcluded <strong>R</strong>egex ) is the regex which defines the <strong>characters</strong> and/or <strong>strings</strong> <strong><code>forbidden</code></strong>, from the <strong>B</strong>egining <strong>R</strong>egex position until a next <strong>S</strong>earch <strong>R</strong>egex match. It, implicitly, defines a <strong>zone</strong>, where the <strong>S</strong>earch <strong>R</strong>egex may occur</p>
</li>
<li>
<p dir="auto"><strong>SR</strong> ( <strong>S</strong>earch <strong>R</strong>egex ) is the regex which defines the expression to <strong>search</strong>, if , both, the <strong>B</strong>egining <strong>R</strong>egex and the <strong>E</strong>xcluded <strong>R</strong>egex are <strong>TRUE</strong></p>
</li>
<li>
<p dir="auto"><strong>RR</strong>  ( <strong>R</strong>eplace <strong>R</strong>egex ) is the regex which defines the expression <strong>replacing</strong> the <strong>S</strong>earch <strong>R</strong>egex</p>
</li>
</ul>
<hr />
<p dir="auto">In your case, we must look for <strong>unnecessary blank</strong> characters, in a <strong><code>&lt;..........&gt;</code></strong> area, without any <strong><code>&lt;</code></strong> nor <strong><code>&gt;</code></strong> inside.  Hence, the <strong>excluded</strong> chars are , simply, the <strong>two</strong> symbols <strong><code>&lt;</code></strong> and <strong><code>&gt;</code></strong></p>
<p dir="auto">Now, inside that area, possibly <strong>multi-lines</strong>, we’ll look for either:</p>
<ul>
<li>
<p dir="auto">Case <strong>A</strong> : <strong>All blank</strong> characters,at <strong>beginning</strong> of lines, in case of a <strong>correct</strong> area, split in <strong>several</strong> lines</p>
</li>
<li>
<p dir="auto">Case <strong>B</strong> : <strong>All blank</strong> characters,at <strong>end</strong> of lines, in case of a <strong>correct</strong> area, split in <strong>several</strong> lines</p>
</li>
<li>
<p dir="auto">Case <strong>C</strong> : <strong>All blank</strong> characters, right <strong>after</strong> the <strong><code>&lt;</code></strong>  symbol</p>
</li>
<li>
<p dir="auto">Case <strong>D</strong> : <strong>All blank</strong> characters, right <strong>before</strong> the <strong><code>&lt;/p&gt;</code></strong> <strong>ending</strong> tag</p>
</li>
<li>
<p dir="auto">Case <strong>E</strong> : <strong>All</strong> ranges of, at least, <strong>two blank</strong> characters, <strong>not</strong> followed from, either, a <strong>blank</strong> char or a <strong><code>&lt;</code></strong> symbol</p>
</li>
</ul>
<p dir="auto">Theses <strong><code>5</code></strong> cases correspond to the different <strong>alternatives</strong> of the <strong>SR</strong> search regex, *<strong>separated</strong> with the <strong><code>|</code></strong> symbol</p>
<p dir="auto">So, we have :</p>
<p dir="auto"><strong>BR</strong> = <strong><code>&lt;p class="oyric"&gt;</code></strong></p>
<p dir="auto"><strong>ER</strong> = <strong><code>&lt;|&gt;</code></strong></p>
<p dir="auto"><strong>SR</strong> = <strong><code>(?:(^\h+)|\h+$|(?&lt;=&gt;)\h+|\h+(?=&lt;/p&gt;)|(\h{2,})(?=[^&lt;\h]))</code></strong></p>
<p dir="auto"><strong>RR</strong> = <strong><code>(?1$0)(?2\x20)</code></strong></p>
<p dir="auto"><strong>Remarks</strong> :</p>
<ul>
<li>
<p dir="auto">The assertion <strong><code>\G</code></strong> is considered as <strong>true</strong> ( <strong>current</strong> position of caret), during the <strong>first</strong> run of the regex. So, if you move the cursor <strong>inside</strong> the <strong>leading</strong> spaces of a line, in <strong>purpose</strong>, before running the reges <strong>S/R</strong>, it could <strong>wrongly</strong> match the <strong>remaining leading</strong> spaces, located <strong>after</strong> the cursor position</p>
</li>
<li>
<p dir="auto">So, in order to <strong>avoid</strong> theses matches, I added, for case <strong>E</strong>, the <strong>restrictive</strong> condition <strong><code>(\h{2,})(?=[^&lt;\h])</code></strong>, which must be <strong>true</strong>, after the <strong>blank matched</strong> range !</p>
</li>
<li>
<p dir="auto">Regarding the <strong>replacement</strong> :</p>
<ul>
<li>
<p dir="auto">If case <strong>A</strong> occurs, we must keep the <strong>leading</strong> spaces, stored in <strong>group<code>1</code></strong> So , we rewrite the <strong>entire</strong> match <strong><code>(?1$0)</code></strong></p>
</li>
<li>
<p dir="auto">If cases <strong>B</strong>, <strong>C</strong> or <strong>D</strong> occurs, we need to delete <strong>all</strong> these <strong>blank</strong> chars =&gt; <strong><code>Nothing</code></strong> is rewritten</p>
</li>
<li>
<p dir="auto">If case <strong>E</strong> occurs, we just replace <strong>all</strong> the <strong>blank</strong> chars matched, stored in <strong>group<code>2</code></strong> with a <strong>single space</strong> character =&gt; <strong><code>(?2\x20)</code></strong></p>
</li>
</ul>
</li>
</ul>
<hr />
<p dir="auto">Finally, we get this <strong>new</strong> regex S/R :</p>
<p dir="auto">SEARCH <strong><code>(?s)(?:\G|&lt;p class="oyric"&gt;)(?:(?!&lt;|&gt;).)*?\K(?:(^\h+)|\h+$|(?&lt;=&gt;)\h+|\h+(?=&lt;/p&gt;)|(\h{2,})(?=[^&lt;\h]))</code></strong></p>
<p dir="auto">REPLACE <strong><code>(?1$0)(?2\x20)</code></strong></p>
<p dir="auto">which should avoid the <strong>side-effects</strong> of my <strong>first</strong> attempt ;-))</p>
<p dir="auto"><strong>Beware</strong></p>
<ul>
<li>
<p dir="auto">If you decide, <strong>before</strong> performing this regex S/R, to <strong>move</strong> the cursor, on <strong>purpose</strong>, inside the  <strong><code>&lt;.........&gt;</code></strong> area of a <strong><code>&lt;p&gt;</code></strong> tag, with a class <strong>different</strong> from <strong><code>oyric</code></strong>, it will, also, match all the <strong>additional blank</strong> characters of that <strong><code>&lt;.........&gt;</code></strong> zone. <strong>Can’t</strong> do anything about this !</p>
</li>
<li>
<p dir="auto">Luckily, once the caret is located <strong>after</strong> that <strong>first</strong> zone <strong><code>&lt;.........&gt;</code></strong>, the behavior of the regex is, again, as <strong>expected</strong> :-))</p>
</li>
</ul>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>PS</strong> :</p>
<p dir="auto">I say, above, regarding the <strong>ER</strong> ( <strong>E</strong>xcluded <strong>R</strong>egex ), that it, <strong>implicitly</strong>, defines a <strong>zone</strong>, where the <strong>S</strong>earch <strong>R</strong>egex may occur</p>
<p dir="auto">Just an example to <strong>explain</strong> this notion. Let’s consider these <strong><code>3</code></strong> simple regexes :</p>
<ul>
<li>
<p dir="auto"><strong><code>[^&lt;&gt;]+(?=\h)</code></strong> , which searches the <strong>greatest</strong> range of chars, different of <strong><code>&lt;</code></strong> and <strong><code>&gt;</code></strong>, if followed with a <strong>blank</strong> char</p>
</li>
<li>
<p dir="auto"><strong><code>[^&lt;]+(?=\h)</code></strong> , which searches the <strong>greatest</strong> range of chars, different of <strong><code>&lt;</code></strong>, if followed with a <strong>blank</strong> char</p>
</li>
<li>
<p dir="auto"><strong><code>[^&gt;]+(?=\h)</code></strong> , which searches the <strong>greatest</strong> range of chars, different of <strong><code>&gt;</code></strong>, if followed with a <strong>blank</strong> char</p>
</li>
</ul>
<p dir="auto">Here is, below, the results, with any <strong>range</strong> of chars, underlined with <strong><code>-</code></strong> and the <strong>blank</strong> char, underlined with <strong><code>^</code></strong></p>
<pre><code class="language-z">                                    REGEX  [^&lt;&gt;]+(?=\h)

&lt;p class="oyric"&gt;This     is    a   test  &lt;/p&gt;   &lt;p class="Tag_3"&gt;bla     blahh &lt;/p&gt;  &lt;p class="oyric"&gt;    a  test&lt;/p&gt;
 -               ------------------------^    --^ -^              -------------^    -^ -^              ------^



                                    REGEX  [^&lt;]+(?=\h)

&lt;p class="oyric"&gt;This     is    a   test  &lt;/p&gt;   &lt;p class="Tag_3"&gt;bla     blahh &lt;/p&gt;  &lt;p class="oyric"&gt;    a  test&lt;/p&gt;
 ----------------------------------------^ -----^ -----------------------------^ ----^ ----------------------^



                                    REGEX  [^&gt;]+(?=\h)

&lt;p class="oyric"&gt;This     is    a   test  &lt;/p&gt;   &lt;p class="Tag_3"&gt;bla     blahh &lt;/p&gt;  &lt;p class="oyric"&gt;    a  test&lt;/p&gt;
--^              ------------------------^    -----^              -------------^    ----^              ------^
</code></pre>
<p dir="auto">As we use the <strong>greedy</strong> quantifier <strong><code>+</code></strong>, it easy to visualize the <strong>complete</strong> zones where it is <strong>allowed</strong> to look for a <strong>blank</strong> character, underlined with <strong><code>^</code></strong>, in <strong>each</strong> case  ;-))</p>
]]></description><link>https://community.notepad-plus-plus.org/post/36205</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/36205</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 11 Nov 2018 12:34:08 GMT</pubDate></item><item><title><![CDATA[Reply to how to remove empty spaces from a particular tag (regular expression) on Sat, 10 Nov 2018 10:04:56 GMT]]></title><description><![CDATA[<p dir="auto">i’m thinking about swiss file knife plugins to build.<br />
<a href="http://stahlworks.com/dev/swiss-file-knife.html" rel="nofollow ugc">http://stahlworks.com/dev/swiss-file-knife.html</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/36196</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/36196</guid><dc:creator><![CDATA[rinku singh]]></dc:creator><pubDate>Sat, 10 Nov 2018 10:04:56 GMT</pubDate></item><item><title><![CDATA[Reply to how to remove empty spaces from a particular tag (regular expression) on Sat, 10 Nov 2018 09:23:38 GMT]]></title><description><![CDATA[<p dir="auto">SEARCH <strong><code>(?s)(\G|&lt;p class="oyric"&gt;)((?!&lt;/p&gt;).)*?\K((?&lt;=&gt;)\h+|\h+(?=&lt;|\h))</code></strong></p>
<p dir="auto">REPLACE  <strong><code>Leave EMPTY</code></strong></p>
<hr />
<p dir="auto">by the way, there is a little problem in your regex, guy038. Now I discover that.</p>
<p dir="auto">Seems that your regex selects all spaces outside the specified tag, and disturb<br />
all my other lines.</p>
<p dir="auto">See a print screen:</p>
<p dir="auto"><a href="https://snag.gy/fRX1ZO.jpg" rel="nofollow ugc">https://snag.gy/fRX1ZO.jpg</a></p>
<p dir="auto">or check regex on this code on notepad:  <a href="https://regex101.com/r/dDBYSk/1" rel="nofollow ugc">https://regex101.com/r/dDBYSk/1</a></p>
<p dir="auto">See what happen after “Replace all”. You will see that all tags with spaces before and after are modify, not only that particular tag  I want.  (&lt;p class=“oyric”&gt;)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/36195</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/36195</guid><dc:creator><![CDATA[Robin Cruise]]></dc:creator><pubDate>Sat, 10 Nov 2018 09:23:38 GMT</pubDate></item><item><title><![CDATA[Reply to how to remove empty spaces from a particular tag (regular expression) on Tue, 30 Oct 2018 14:49:39 GMT]]></title><description><![CDATA[<p dir="auto">GREAT ! thank you very much ;)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/35867</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/35867</guid><dc:creator><![CDATA[Robin Cruise]]></dc:creator><pubDate>Tue, 30 Oct 2018 14:49:39 GMT</pubDate></item><item><title><![CDATA[Reply to how to remove empty spaces from a particular tag (regular expression) on Tue, 30 Oct 2018 19:40:56 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/robin-cruise" aria-label="Profile: Robin-cruise">@<bdi>Robin-cruise</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">You were not very <strong>far</strong> from the <strong>right</strong> solution ! The way to <strong>replace</strong> something :</p>
<ul>
<li>
<p dir="auto">In a particular <strong>tag</strong> section, as <strong><code>&lt;p&gt;........&lt;/p&gt;</code></strong></p>
</li>
<li>
<p dir="auto">In a particular <strong>tag</strong> section, with a particular <strong>class</strong> name, as <strong><code>&lt;p class="test"&gt;Bla  bla blah&lt;/p&gt; </code></strong></p>
</li>
</ul>
<p dir="auto">has already been <strong>discussed</strong> in these posts :</p>
<p dir="auto"><a href="https://notepad-plus-plus.org/community/topic/15058/regex-remove-particular-words-from-tags-in-several-text-pages/10" rel="nofollow ugc">https://notepad-plus-plus.org/community/topic/15058/regex-remove-particular-words-from-tags-in-several-text-pages/10</a></p>
<p dir="auto"><a href="https://notepad-plus-plus.org/community/topic/15058/regex-remove-particular-words-from-tags-in-several-text-pages/12" rel="nofollow ugc">https://notepad-plus-plus.org/community/topic/15058/regex-remove-particular-words-from-tags-in-several-text-pages/12</a></p>
<hr />
<p dir="auto">So, the <strong>general</strong> regex solution, when you want to perform a <strong>Search/Replacement</strong>, ONLY in an <strong>area</strong>, which is located <strong>between</strong> two <strong>particular</strong> boundaries, is :</p>
<p dir="auto">SEARCH <strong><code>(?-s)(\G|</code>BR<code>)((?!</code>ER<code>).)*?\K</code>SR</strong>        OR        <strong><code>(?s)(\G|</code>BR<code>)((?!</code>ER<code>).)*?\K</code>SR</strong></p>
<p dir="auto">REPLACE <strong>RR</strong></p>
<p dir="auto">where :</p>
<ul>
<li>
<p dir="auto"><strong>BR</strong> ( <strong>B</strong>egining <strong>R</strong>egex ) is the regex which defines the <strong>start</strong> of the <strong>defined</strong> zone, for the <strong>search/replacement</strong></p>
</li>
<li>
<p dir="auto"><strong>ER</strong> ( <strong>E</strong>nding <strong>R</strong>egex ) is the regex which defines the <strong>end</strong> of the <strong>defined</strong> zone, for the <strong>search/replacement</strong></p>
</li>
<li>
<p dir="auto"><strong>SR</strong> ( <strong>S</strong>earch <strong>R</strong>egex ) is the regex which defines the expression to <strong>search</strong>, in any <strong>defined</strong> zone</p>
</li>
<li>
<p dir="auto"><strong>RR</strong>  ( <strong>R</strong>eplace <strong>R</strong>egex ) is the regex which defines the expression <strong>replacing</strong> the <strong>S</strong>earch <strong>R</strong>egex, in any <strong>defined</strong> zone</p>
</li>
</ul>
<p dir="auto">In your case :</p>
<p dir="auto"><strong>BR</strong> = <strong><code>&lt;p class="oyric"&gt;</code></strong></p>
<p dir="auto"><strong>ER</strong> = <strong><code>&lt;/p&gt;</code></strong></p>
<p dir="auto"><strong>SR</strong> = <strong><code>((?&lt;=&gt;)\h+|\h+(?=&lt;|\h))</code></strong></p>
<p dir="auto"><strong>RR</strong> = <strong><code>Nothing</code></strong></p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto"><strong>SR</strong> is a search of any of the two <strong>alternatives</strong>, separated with the <strong><code>|</code></strong> symbol, and surrounded by <strong>parentheses</strong>, because of the <strong>lowest</strong> priority of the <strong>alternation</strong> symbol <strong><code>|</code></strong></p>
<ul>
<li>
<p dir="auto"><strong><code>(?&lt;=&gt;)\h+</code></strong> which tries to match any <strong>non-null</strong> range of <strong>horizontal blank</strong> chars ( <strong>spaces</strong> or <strong>tabulations</strong> ), if <strong>preceded</strong> with the <strong><code>&gt;</code></strong> symbol</p>
</li>
<li>
<p dir="auto"><strong><code>\h+(?=&lt;|\h))</code></strong> which tries to match any <strong>non-null</strong> range of <strong>horizontal blank</strong> chars ( <strong>spaces</strong> or <strong>tabulations</strong> ), if <strong>followed</strong> by, either, the <strong><code>&lt;</code></strong> symbol or a final <strong>horizontal blank</strong> character</p>
</li>
</ul>
</li>
<li>
<p dir="auto">As all these <strong>blank</strong> characters matched have to be <strong>deleted</strong>, the <strong>replacement</strong> zone is just <strong>empty</strong></p>
</li>
<li>
<p dir="auto"><strong>First</strong>, the regex tries to find the string <strong><code>&lt;p class="oyric"&gt;</code></strong>, followed by the <strong>shortest</strong> range, even <strong>null</strong>, of characters, <strong><code>.*?</code></strong>, till the <strong>search</strong> regex, explained above, with the condition that the string <strong><code>&lt;/p&gt;</code></strong> must <strong>not</strong> located at <strong>any</strong> position of this range</p>
</li>
<li>
<p dir="auto">Due to the <strong><code>\K</code></strong> syntax, the regex engine <strong>resets</strong> its working location and forgets any <strong>previous</strong> match. So the <strong>final</strong> match is ,simply, the part described above <strong><code>((?&lt;=&gt;)\h+|\h+(?=&lt;|\h))</code></strong> ( <strong>SR</strong> )</p>
</li>
<li>
<p dir="auto">After this <strong>first</strong> match, it can only match the <strong>zero-length</strong> assertion <strong><code>\G</code></strong>, followed, again, with a possible other <strong>shortest</strong> range, even <strong>null</strong> … … … as just above !</p>
</li>
<li>
<p dir="auto">When the regex engine skips the <strong>ending</strong> boundary <strong><code>&lt;/p&gt;</code></strong>, the <strong><code>\G</code></strong> <strong>cannot</strong> be verified anymore and the <strong>only</strong> way to <strong>match</strong> something else is to grab, again, a <strong><code>&lt;p class="oyric"&gt;</code></strong> string, <strong>further on</strong> !</p>
</li>
<li>
<p dir="auto">If you are only interested in <strong>single-line</strong> ranges <strong><code>BR.........ER</code></strong>, use the <strong><code>(?-s)</code></strong> <strong>modifier</strong>, at beginning of the <strong>search</strong> regex</p>
</li>
<li>
<p dir="auto">If you may have some <strong>multi-lines</strong> ranges <strong><code>BR.........ER</code></strong>, use the <strong><code>(?s)</code></strong> <strong>modifier</strong>, at beginning of the <strong>search</strong> regex</p>
</li>
</ul>
<hr />
<p dir="auto">So, <strong>Robin</strong>, let’s imagine the <strong>sample</strong> text, below :</p>
<pre><code class="language-diff">&lt;p class="oyric"&gt;  Laurie Strode comes to   her final confrontation      with Michael Myers, the   masked figure  who has haunted her     since she narrowly escaped.  &lt;/p&gt;

&lt;p class="Tag_1"&gt;  Laurie Strode comes to   her final confrontation      with Michael Myers, the   masked figure  who has haunted her     since she narrowly escaped.  &lt;/p&gt;

&lt;p class="oyric"&gt;            Laurie Strode         comes to her final confrontation with Michael     Myers, the masked figure  who has              haunted her since she            narrowly escaped.&lt;/p&gt;

&lt;p class="Tag_2"&gt;bla    blah     blah   &lt;/p&gt;

&lt;p class="oyric"&gt;  This is    a test &lt;/p&gt;   &lt;p class="Tag_3"&gt;bla       blah   blah &lt;/p&gt;  &lt;p class="oyric"&gt;  The    final   test   &lt;/p&gt;


&lt;p class="oyric"&gt;  Laurie Strode comes to   her final
 confrontation      
 with Michael Myers, the   masked
 figure  who has haunted her     since she
 narrowly escaped.  &lt;/p&gt;

&lt;p class="Tag_2"&gt;bla
    blah     
....blah   &lt;/p&gt;

&lt;p class="oyric"&gt;     This is    an           
     other  test to verify    if the      regex
           is correct         &lt;/p&gt;
</code></pre>
<p dir="auto">Using the following regex S/R :</p>
<p dir="auto">SEARCH <strong><code>(?s)(\G|&lt;p class="oyric"&gt;)((?!&lt;/p&gt;).)*?\K((?&lt;=&gt;)\h+|\h+(?=&lt;|\h))</code></strong></p>
<p dir="auto">REPLACE <strong><code>Leave EMPTY</code></strong></p>
<p dir="auto">You should get the expected text, below :</p>
<pre><code class="language-diff">&lt;p class="oyric"&gt;Laurie Strode comes to her final confrontation with Michael Myers, the masked figure who has haunted her since she narrowly escaped.&lt;/p&gt;

&lt;p class="Tag_1"&gt;  Laurie Strode comes to   her final confrontation      with Michael Myers, the   masked figure  who has haunted her     since she narrowly escaped.  &lt;/p&gt;

&lt;p class="oyric"&gt;Laurie Strode comes to her final confrontation with Michael Myers, the masked figure who has haunted her since she narrowly escaped.&lt;/p&gt;

&lt;p class="Tag_2"&gt;bla    blah     blah   &lt;/p&gt;

&lt;p class="oyric"&gt;This is a test&lt;/p&gt;   &lt;p class="Tag_3"&gt;bla       blah   blah &lt;/p&gt;  &lt;p class="oyric"&gt;The final test&lt;/p&gt;


&lt;p class="oyric"&gt;Laurie Strode comes to her final
 confrontation 
 with Michael Myers, the masked
 figure who has haunted her since she
 narrowly escaped.&lt;/p&gt;

&lt;p class="Tag_2"&gt;bla
    blah     
....blah   &lt;/p&gt;

&lt;p class="oyric"&gt;This is an 
 other test to verify if the regex
 is correct&lt;/p&gt;
</code></pre>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">It’s easy to verify that <strong>blank</strong> characters have been removed, <strong>ONLY</strong> in <strong>all</strong> areas <strong><code>&lt;p class="oyric"&gt;..........&lt;/p&gt;</code></strong>, whatever they were <strong>single-line</strong> areas or a <strong>multi-lines</strong> blocks</p>
</li>
<li>
<p dir="auto">However, note that if a line ends with <strong>blank</strong> chars and the <strong>next</strong> line begins, also, with <strong>blank</strong> characters, this regex S/R will keep <strong>one</strong> blank char, either, at the <strong>end</strong> of this line and at the <strong>beginning</strong> of the <strong>next</strong> line !</p>
</li>
<li>
<p dir="auto">Finally, beware that, if words are separated with a <strong>mix</strong> of <strong>space</strong> and <strong>tabulation</strong> characters, only the <strong>final</strong> blank character will be <strong>kept</strong> !</p>
</li>
</ul>
<p dir="auto">For instance from text :</p>
<pre><code class="language-diff">&lt;p class="oyric"&gt;	   		Test	  	    #1  	    &lt;/p&gt;  ( Last BLANK char = SPACE      ,before #1 )

&lt;p class="oyric"&gt;   	    Test  	  		#2		  	&lt;/p&gt;  ( Last BLANK char = TABULATION, before #2 )
</code></pre>
<p dir="auto">You’ll obtain :</p>
<pre><code class="language-diff">&lt;p class="oyric"&gt;Test #1&lt;/p&gt;   ( SPACE      char between Test and #1 )

&lt;p class="oyric"&gt;Test	#2&lt;/p&gt; ( TABULATION char between Test and #2 )
</code></pre>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/35859</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/35859</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 30 Oct 2018 19:40:56 GMT</pubDate></item></channel></rss>