<?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[Regular Expression, end of line]]></title><description><![CDATA[<p dir="auto">I thought '$ would batch end-of-line?</p>
<p dir="auto">But searching for ‘:[^:]*$’ using Regular expression in below sample text shows that is matches across multiple lines. Is this correct behaviour?</p>
<p dir="auto">sample text:<br />
ABC:DEF:GHI<br />
JKL<br />
MNO<br />
PQR:STU:VWX</p>
<p dir="auto">match after searching with above regexp :<br />
:GHI<br />
JKL<br />
MNO</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/18978/regular-expression-end-of-line</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 00:28:40 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/18978.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Feb 2020 09:58:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regular Expression, end of line on Thu, 27 Feb 2020 19:26:51 GMT]]></title><description><![CDATA[<p dir="auto">Hi, @@luuk-v, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> and <strong>All</strong>,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-r">@<bdi>Terry-r</bdi></a> said :</p>
<blockquote>
<p dir="auto">Personally though my alternate regex works I would use <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> one as it is more readable and possibly also more defined!</p>
</blockquote>
<p dir="auto">In the <strong>same</strong> way, I would say that <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a>’s solution is <strong>clever</strong> too and is, finally, very <strong>easy</strong> to interpret ;-))</p>
<p dir="auto">Indeed, this <strong>new</strong> syntax <strong><code>:[^:]*?$</code></strong> finds a <strong>colon</strong> char, followed with the <strong>shortest</strong> range of characters, possibly <strong>null</strong>, <strong>different</strong> from a <strong>colon</strong>, before an <strong>end</strong> of line !</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/51018</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/51018</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 27 Feb 2020 19:26:51 GMT</pubDate></item><item><title><![CDATA[Reply to Regular Expression, end of line on Thu, 27 Feb 2020 18:40:50 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 in <a href="/post/51005">Regular Expression, end of line</a>:</p>
<blockquote>
<p dir="auto">the correct regex to process should be :[^:\r\n]*$</p>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/luuk-v" aria-label="Profile: Luuk-v">@<bdi>Luuk-v</bdi></a> , Another regex which would also have produced the same answer is<br />
<code>:[^:]*?$</code><br />
Note the addition of the <code>?</code> behind the <code>*</code>. It turns a “greedy” operator into a “non-greedy” (minimalist) operator. So this would stop at the very first instance of the <code>EOL</code> character(s).<br />
Also note that although you used the <code>$</code> character as an end of line marker outside of the negative class it does NOT work inside.</p>
<p dir="auto">Personally though my alternate regex works I would use <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> one as it is more readable and possibly also more defined!</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/51014</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/51014</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Thu, 27 Feb 2020 18:40:50 GMT</pubDate></item><item><title><![CDATA[Reply to Regular Expression, end of line on Thu, 27 Feb 2020 15:37:35 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/luuk-v" aria-label="Profile: luuk-v">@<bdi>luuk-v</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">As <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> said, the simple <strong>negative class</strong> <strong><code>[^:]</code></strong>  will match <strong>absolutely any</strong> character which is <strong>different</strong>  from a <strong>colon</strong> symbol <strong><code>:</code></strong>, including possible <strong>EOL</strong> characters as <strong><code>\n</code></strong> and <strong><code>\r</code></strong> !</p>
<p dir="auto">So assuming your <strong>sample</strong> text :</p>
<pre><code class="language-diff">ABC:DEF:GHI
JKL
MNO
PQR:STU:VWX
</code></pre>
<p dir="auto">With your regex <strong><code>:[^:]*$</code></strong> :</p>
<ul>
<li>
<p dir="auto">First, the part <strong><code>:</code></strong> searches for a <strong>literal colon</strong> char</p>
</li>
<li>
<p dir="auto">Then, the part <strong><code>[^:]*</code></strong> for the <strong>greatest</strong> range, possibly <strong>null</strong>, of characters <strong>all</strong> different from a <strong>colon</strong>, including <strong>EOL</strong> chars</p>
</li>
<li>
<p dir="auto">But <em>ONLY IF</em>  that range <strong>ends</strong> the <strong>current</strong> line, because of the <strong><code>$</code></strong> <strong>assertion</strong></p>
</li>
</ul>
<p dir="auto">This explains why your regex selects <strong>all</strong> the zone <strong><code>:GHI...........MNO</code></strong>.</p>
<p dir="auto">You could say “But, WHY it does <strong>not</strong> select the <strong>EOL</strong> chars of line <strong><code>MNO</code></strong> and, also, the string <strong><code>PQR</code></strong> right before a <strong>colon</strong> char ?”. Note that I asked myself the <strong>same</strong> question ;-)</p>
<ul>
<li>
<p dir="auto">It <strong>cannot</strong> match the <strong>EOL</strong> chars of line <strong><code>MNO</code></strong> as, in that case the <strong><code>$</code></strong> assertion would <strong>not</strong> be verified. Indeed, after the <strong>EOL</strong> chars of line <strong><code>MNO</code></strong>, there is <strong>not</strong> an <strong>end</strong> of line but the letter <strong><code>P</code></strong> of the <strong>next</strong> line !</p>
</li>
<li>
<p dir="auto">And it <strong>cannot</strong> match the string <strong><code>PQR</code></strong>, too, because the string <strong><code>PQR</code></strong> is <strong>not</strong> immediately followed with an <strong>end</strong> of line !</p>
</li>
</ul>
<hr />
<p dir="auto">So, the <strong>correct</strong> regex to process should be <strong><code>:[^:\r\n]*$</code></strong> which selects <strong>only</strong> the strings <strong><code>:GHI</code></strong> and <strong><code>:VWX</code></strong>, <strong>ending</strong> their lines, which is, probably, the result that you <strong>expect</strong> to, don’t you ?</p>
<p dir="auto">Best regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/51005</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/51005</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 27 Feb 2020 15:37:35 GMT</pubDate></item><item><title><![CDATA[Reply to Regular Expression, end of line on Thu, 27 Feb 2020 10:26:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/luuk-v" aria-label="Profile: Luuk-v">@<bdi>Luuk-v</bdi></a> said in <a href="/post/51001">Regular Expression, end of line</a>:</p>
<blockquote>
<p dir="auto">Is this correct behaviour?</p>
</blockquote>
<p dir="auto">Unfortunately yes. When you use a negative class such as your <code>[^:]</code> you are saying anything but the : character, and that includes an end of line character.</p>
<p dir="auto">So once you regex finds the first : it then grabs other characters until it reaches the next :. The next part requires it to also have an end of line <code>$</code>, so it backs up until the last one found and stops there.</p>
<p dir="auto">You might want to read<br />
<a href="https://npp-user-manual.org/docs/searching/#regular-expressions" rel="nofollow ugc">https://npp-user-manual.org/docs/searching/#regular-expressions</a><br />
Look for “The complement of the characters” which states this. To avoid a multi line capture you also need to include in the negative class the end of line character.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/51003</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/51003</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Thu, 27 Feb 2020 10:26:13 GMT</pubDate></item></channel></rss>