<?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[Regex pattern needed]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I am looking for a way to replace all lines of the form:<br />
<code>https://www.server.example/path/something%20with%20spaces</code><br />
with:<br />
<code>&lt;a href="https://www.server.example/path/something%20with%20spaces"&gt;something with spaces&lt;/a&gt;</code><br />
Using a single search/replace operation.</p>
<p dir="auto">Currently I do it with one operation that transforms the link to an <code>&lt;h ref...&gt;</code> format, and another one to replace a <code>%20</code> with a space after the closing angle bracket, which has to be repeated several times until all the <code>%20</code> instances are replaced.</p>
<p dir="auto">Please assist.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20977/regex-pattern-needed</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 21:40:32 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20977.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 01 Apr 2021 20:47:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex pattern needed on Fri, 02 Apr 2021 15:04:06 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> said in <a href="/post/64577">Regex pattern needed</a>:</p>
<blockquote>
<p dir="auto">Or maybe I will find some time this evening.</p>
</blockquote>
<p dir="auto">Well, it was the next day, but…</p>
<p dir="auto">My mistake in yesterday’s modified <strong>BSR</strong> = <code>&lt;a[^\s&gt;]*&gt;</code> was including <code>\s</code> in the complement character class, which meant it had to be <code>&lt;a...&gt;</code> <em>without any spaces</em>, which obviously cannot match <code>&lt;a href="..."&gt;</code>.  Once I realized that, it was easy to fix.</p>
<ul>
<li>BSR = <code>&lt;a[^&gt;]*&gt;</code></li>
<li>ESR = <code>&lt;/a&gt;</code></li>
<li>FR = <code>%20</code></li>
<li>RR = <code>\x20</code> (or literal space)</li>
<li>FIND = <code>(?-i:&lt;a[^&gt;]*&gt;|(?!\A)\G)(?s:(?!&lt;/a&gt;).)*?\K(?-i:%20)</code></li>
<li>REPLACE = <code>\x20</code></li>
<li>Final Transformation of my previous data:<pre><code>&lt;a href="https://www.server.example/path/something%20with%20spaces"&gt;something with spaces&lt;/a&gt;
&lt;a href="https://www.different.example/path/one%20space"&gt;one space&lt;/a&gt;
&lt;a href="https://www.third.example/path/spaceless"&gt;spaceless&lt;/a&gt;
</code></pre>
</li>
</ul>
]]></description><link>https://community.notepad-plus-plus.org/post/64593</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64593</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 02 Apr 2021 15:04:06 GMT</pubDate></item><item><title><![CDATA[Reply to Regex pattern needed on Thu, 01 Apr 2021 21:19:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alexolog" aria-label="Profile: alexolog">@<bdi>alexolog</bdi></a> ,</p>
<p dir="auto">I would approach it as a two-step process.</p>
<ol>
<li>convert <code>https://www.server.example/path/something%20with%20spaces</code> to <code>&lt;a href="https://www.server.example/path/something%20with%20spaces"&gt;something%20with%20spaces&lt;/a&gt;</code> – because that’s a pretty easy regex</li>
<li>convert the <code>&gt;something%20with%20spaces&lt;/a&gt;</code> to <code>&gt;something with spaces&lt;/a&gt;</code></li>
</ol>
<p dir="auto">I would do this because I assume that some of your URLs might have one %20, some might have two %20, and some might have more (or none).  And coding a regex for all those edge cases is fragile. OTOH, if I can just search for a URL and break it into two pieces, that’s easy.</p>
<pre><code>https://www.server.example/path/something%20with%20spaces
https://www.different.example/path/one%20space
https://www.third.example/path/spaceless
</code></pre>
<ol>
<li>FIND = <code>(?-s)^(https?://\S*/)([^"\s/]*)$</code><br />
REPLACE = <code>&lt;a href="$1$2"&gt;$2&lt;/a&gt;</code><br />
MODE = Regular expression</li>
</ol>
<pre><code>&lt;a href="https://www.server.example/path/something%20with%20spaces"&gt;something%20with%20spaces&lt;/a&gt;
&lt;a href="https://www.different.example/path/one%20space"&gt;one%20space&lt;/a&gt;
&lt;a href="https://www.third.example/path/spaceless"&gt;spaceless&lt;/a&gt;
</code></pre>
<p dir="auto">2 . For this one, I would use <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>’s generic “change data, but only between start and end markers” regex from <a href="/post/62799">this post</a><br />
* Generic = <code>(?-i:</code><strong>BSR</strong><code>|(?!\A)\G)(?s:(?!</code><strong>ESR</strong><code>).)*?\K(?-i:</code><strong>FR</strong><code>)</code><br />
* BSR =  <code>&gt;</code> (for the end of the <code>&lt;a href="..."&gt;</code>)<br />
* ESR = <code>&lt;/a&gt;</code><br />
* FR = <code>%20</code><br />
* RR = <code>\x20</code> (or a literal space<br />
* =&gt; FIND = <code>(?-i:&gt;|(?!\A)\G)(?s:(?!&lt;/a&gt;).)*?\K(?-i:%20)</code><br />
REPLACE = <code>\x20</code> (or a literal space)</p>
<p dir="auto">Unfortunately, when I did that, my test data became</p>
<pre><code>&lt;a href="https://www.server.example/path/something%20with%20spaces"&gt;something with spaces&lt;/a&gt;
&lt;a href="https://www.different.example/path/one space"&gt;one space&lt;/a&gt;
&lt;a href="https://www.third.example/path/spaceless"&gt;spaceless&lt;/a&gt;
</code></pre>
<p dir="auto">… and you can see that it replaced a %20 that was inside the href portion… I think because used such a small BSR expression.  Unfortunately, my attempt at fixing it with BSR = <code>&lt;a[^\s&gt;]*&gt;</code>, to be more specific, said it couldn’t find it at all.  And unfortunately, I have to focus on my day job a bit more today, so  I cannot continue debugging.  But this is the path I’d follow.</p>
<p dir="auto">Maybe <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> will have time to tell us what I did wrong, or come up with a better BSR to keep the find-region out of the href value.  Or maybe I will find some time this evening.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/64577</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/64577</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 01 Apr 2021 21:19:59 GMT</pubDate></item></channel></rss>