<?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 to match spaces in a URL]]></title><description><![CDATA[<p dir="auto">I want to replace spaces in URLs in src attributes using a regex e.g.<br />
src="http :// jos / bos " (remove spaces in string between the quotes)</p>
<p dir="auto">I found this regex to select the string between the quotes on <a href="http://regexr.com" rel="nofollow ugc">regexr.com</a>.<br />
(?![src=“]).*(?=”)</p>
<p dir="auto">When I use this regex in Notepad++, it doesn’t match.</p>
<p dir="auto">Also, if I replace .* with a space but this is due to my poor regex skills.</p>
<p dir="auto">Any help appreciated, kr.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20440/regex-to-match-spaces-in-a-url</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Jul 2026 13:52:57 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20440.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 Dec 2020 10:40:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex to match spaces in a URL on Mon, 07 Dec 2020 12:55:48 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/progonkpa" aria-label="Profile: progonkpa">@<bdi>progonkpa</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">I suppose that the following <strong>regex</strong> S/R sould do the job !</p>
<p dir="auto">SEARCH <strong><code>(?-is)(?:&lt;img\x20+src="\K|\G)(?:\x20*([^"\x20\r\n]+)|\x20+)</code></strong></p>
<p dir="auto">REPLACE <strong><code>\1</code></strong></p>
<p dir="auto"><strong>Remarks</strong> :</p>
<ul>
<li>
<p dir="auto">Due to the <strong><code>\G</code></strong> syntax, the <strong>initial</strong> location of the <strong>cursor</strong> must <strong>not</strong> be followed with <strong>space</strong> characters</p>
</li>
<li>
<p dir="auto">Tick the <strong><code>Wrap around</code></strong> option</p>
</li>
<li>
<p dir="auto">Select the <strong><code>Regular expression</code></strong> search mode</p>
</li>
<li>
<p dir="auto">Because of the <strong><code>\K</code></strong> syntax, click on the <strong><code>Replace All</code></strong> button, <strong>exclusively</strong>. ( <strong>Do not</strong> use the <strong><code>Replace</code></strong> button ! )</p>
</li>
</ul>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>If we use the <strong>Free-spacing</strong> mode <strong><code>(?x)</code></strong>, this regex can be expressed as :</li>
</ul>
<pre><code class="language-z">(?x-is) (?: &lt;img \x20+ src="  \K  | \G )  (?: \x20*  ( [^"\x20\r\n]+ )  |  \x20+ )
</code></pre>
<ul>
<li>
<p dir="auto">So the regex engine is looking for a string <strong><code>&lt;img src="</code></strong>, <strong>first</strong>, with this <strong>exact</strong> case</p>
</li>
<li>
<p dir="auto">Then , due the <strong><code>\K</code></strong> syntax, anything being <strong>matched</strong>, so far, is <strong>canceled</strong> and the regex engine, now, searches, <strong>either</strong>, for :</p>
<ul>
<li>
<p dir="auto">A <strong>non-null</strong> range of <strong>non-space</strong> characters, possibly preceded by <strong>space</strong> chars</p>
</li>
<li>
<p dir="auto">A <strong>non-null</strong> range of <strong>space</strong> characters</p>
</li>
</ul>
</li>
<li>
<p dir="auto">Then, due the <strong><code>\G</code></strong> syntax, it searches, for the <strong>same</strong> ranges, as above, <strong>right after</strong> the location of the <strong>last</strong> match. If a match <strong>cannot</strong> be found, it tries, again, to find an <strong>other</strong> string <strong><code>&lt;img src="</code></strong> and so on…</p>
</li>
<li>
<p dir="auto">Note that the <strong><code>(?:...........)</code></strong> structures are <strong>non-capturing</strong> groups which do <strong>not</strong> store anything for further use, either, in <strong>search</strong> and/or <strong>replacement</strong> !</p>
</li>
<li>
<p dir="auto">In replacement, we <strong>only</strong> rewrite the <strong>non-space</strong> characters <strong><code>[^"\x20\r\n]+</code></strong> stored in <strong>group <code>1</code></strong></p>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/60531</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/60531</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Mon, 07 Dec 2020 12:55:48 GMT</pubDate></item></channel></rss>