<?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 start of line doesn&#x27;t work as expected]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I am trying to remove the first character of each line on a block of text. I’d expect “^.” to get the job done, while it clears everything, as an iteration were taking place.</p>
<p dir="auto">Any clues?</p>
<p dir="auto">TIA</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/18011/regex-start-of-line-doesn-t-work-as-expected</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 01:57:52 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/18011.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 28 Jul 2019 09:13:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Tue, 30 Jul 2019 00:12:13 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:</p>
<blockquote>
<p dir="auto">if the user tried a couple of single "replace"s to make sure it was working, and then hit “replace all”, and the behavior changed, that would be disturbing</p>
</blockquote>
<p dir="auto">Ha! I’m surprised that <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> hasn’t jumped in yet to talk about how exactly this sort of thing can and does happen!!  :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/45768</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45768</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 30 Jul 2019 00:12:13 GMT</pubDate></item><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Mon, 29 Jul 2019 22:36:47 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:</p>
<blockquote>
<p dir="auto">For example, making “replace all” behave more like a repeated “find next/replace”: if the user tried a couple of single "replace"s to make sure it was working, and then hit “replace all”, and the behavior <strong>changed</strong>, that would be disturbing to the majority of users.</p>
</blockquote>
<p dir="auto">I didn’t consider this.</p>
<p dir="auto">Thanks for your thoughts Peter.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/45765</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45765</guid><dc:creator><![CDATA[Salvatore Falcone]]></dc:creator><pubDate>Mon, 29 Jul 2019 22:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Mon, 29 Jul 2019 21:49:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/salvatore-falcone" aria-label="Profile: Salvatore-Falcone">@<bdi>Salvatore-Falcone</bdi></a> said:</p>
<blockquote>
<p dir="auto"><code>^.(.)</code> is enough.</p>
</blockquote>
<p dir="auto">Yes, because it moves the cursor beyond the first character of the line, so now <code>^</code> isn’t matching at the current cursor position, and it needs to move forward to</p>
<blockquote>
<p dir="auto">Still disturbing to me ;-)</p>
</blockquote>
<p dir="auto">Probably best to think of it not as the /g switch, but as looping on rerunning the regex from a new start point, until it’s hit the end of the document (or wrapped around back to the start of your search).  An editor can be a different environment than other programs; and adding in the hooks for interactivity (like “find next / replace” along with “replace all”) changes the way that it has to think about the current position, global matches, etc.</p>
<p dir="auto">For example, making “replace all” behave more like a repeated “find next/replace”: if the user tried a couple of single "replace"s to make sure it was working, and then hit “replace all”, and the behavior <strong>changed</strong>, that would be disturbing to the majority of users.</p>
<p dir="auto">Many Notepad++ users don’t come from a programming/regex background – as is obvious by the number of “how do I search-and-replace ___” questions we see here, without any attempt at a regex given – and Notepad++ walks the fine line between making things easy for general-users, but with enough features for the super-users.  I think it does a good job of that.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/45762</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45762</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 29 Jul 2019 21:49:23 GMT</pubDate></item><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Mon, 29 Jul 2019 21:13:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> said:</p>
<blockquote>
<p dir="auto">So, I guess you are looking for something like<br />
find what:<code>^.(.*)$</code><br />
replace with <code>\1</code></p>
</blockquote>
<p dir="auto">Actually I found out that<br />
find what: <code>^.(.)</code><br />
replace with: <code>\1</code><br />
is enough.</p>
<p dir="auto">Still disturbing to me ;-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/45759</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45759</guid><dc:creator><![CDATA[Salvatore Falcone]]></dc:creator><pubDate>Mon, 29 Jul 2019 21:13:54 GMT</pubDate></item><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Mon, 29 Jul 2019 20:48:20 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:</p>
<blockquote>
<p dir="auto">It seems “polite” to me.  Eko said it all with “once the first char has been removed, the next char is the first again”.</p>
</blockquote>
<p dir="auto">I’ll try to be more explicit. You are portraying an iteration, while standard behaviour is to match the rule, substitute, and carry on through the string (if the <code>g</code> -for global- option is set, as I expect it to be when replacing text). If you do apply those simple steps, you shouldn’t need to catch anything when using <code>^.</code>, as “beginning of line” should be parsed once for each line.</p>
<blockquote>
<p dir="auto">See <a href="https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation" rel="nofollow ugc">https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation</a></p>
</blockquote>
<p dir="auto">Thank you for the pointers!</p>
<p dir="auto">Cheers</p>
]]></description><link>https://community.notepad-plus-plus.org/post/45758</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45758</guid><dc:creator><![CDATA[Salvatore Falcone]]></dc:creator><pubDate>Mon, 29 Jul 2019 20:48:20 GMT</pubDate></item><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Mon, 29 Jul 2019 20:10:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/salvatore-falcone" aria-label="Profile: Salvatore-Falcone">@<bdi>Salvatore-Falcone</bdi></a> said:</p>
<blockquote>
<p dir="auto">this doesn’t feel as a polite behaviour from N++</p>
</blockquote>
<p dir="auto">It seems “polite” to me.  Eko said it all with “once the first char has been removed, the next char is the first again”.</p>
<blockquote>
<p dir="auto">Which regex flavour is it compliant to?</p>
</blockquote>
<p dir="auto">See <a href="https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation" rel="nofollow ugc">https://notepad-plus-plus.org/community/topic/15765/faq-desk-where-to-find-regex-documentation</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/45756</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45756</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 29 Jul 2019 20:10:45 GMT</pubDate></item><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Mon, 29 Jul 2019 19:22:34 GMT]]></title><description><![CDATA[<p dir="auto">Thank you guys for the explanations and solutions. Nontheless, this doesn’t feel as a <em>polite</em> behaviour from N++. Which regex flavour is it compliant to?</p>
<p dir="auto">Just for the rec, here’s a posix tool in action:</p>
<pre><code>~$ echo "&gt;&gt; test line 1" &gt; test.txt
~$ echo "&gt;&gt; test line 2" &gt;&gt; test.txt
~$ cat test.txt
&gt;&gt; test line 1
&gt;&gt; test line 2
~$ sed 's ^.  ' test.txt
&gt; test line 1
&gt; test line 2
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/45754</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45754</guid><dc:creator><![CDATA[Salvatore Falcone]]></dc:creator><pubDate>Mon, 29 Jul 2019 19:22:34 GMT</pubDate></item><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Tue, 30 Jul 2019 08:50:00 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/salvatore-falcone" aria-label="Profile: salvatore-falcone">@<bdi>salvatore-falcone</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Here are a solution :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?-s)^.(.?)</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>\1</code></strong></p>
</li>
<li>
<p dir="auto"><strong>Tick</strong> the <strong><code>Wrap around</code></strong> option, if necessary</p>
</li>
<li>
<p dir="auto">Select the <strong><code>Regular expression</code></strong> search mode</p>
</li>
<li>
<p dir="auto">Click <strong>once</strong> on the <strong><code>Replace All</code></strong> button or <strong>several</strong> times on the <strong><code>Replace</code></strong> button</p>
</li>
</ul>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">The <strong><code>(?-s)</code></strong> is a in-line <strong>modifier</strong>, which forces the <strong>regex</strong> engine to interprets the <strong>dot</strong> symbol ( <strong><code>.</code></strong> ) as a <strong>standard</strong> character <strong>only</strong>, ( not <strong>EOL</strong> chars ! )</p>
</li>
<li>
<p dir="auto">The <strong><code>^</code></strong> symbol is a <strong>zero-length</strong> assertion, which is the location of the <strong>beginning</strong> of <strong>current</strong> line scanned</p>
</li>
<li>
<p dir="auto">In <strong>replacement</strong>, we just rewrite <strong>group <code>1</code></strong>, only. So, the <strong>second</strong> standard character of <strong>current</strong> line, if <strong>any</strong> !</p>
</li>
</ul>
<p dir="auto"><strong>IMPORTANT</strong> :</p>
<p dir="auto">Why can we search for the <strong>first</strong> character of each line, if any, with the simple regex <strong><code>(?-s)^.</code></strong> and why we need an <strong>other</strong> syntax when we want to <strong>delete</strong> this <strong>first</strong> character ? <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: ekopalypse">@<bdi>ekopalypse</bdi></a> already answered the <strong>reason</strong> why !</p>
<p dir="auto">When we just search for the <strong>first</strong> character of lines, after a <strong>match</strong>, the <strong>current</strong> location is <strong>always</strong> after this <strong>first</strong> char. So, in order to verify the <strong><code>^</code></strong> assertion of the regex, we need, necessarily, to <strong>jump</strong> to the <strong>next</strong> line and match the <strong>first</strong> character of this line</p>
<p dir="auto">But, when we, really, <strong>delete</strong> the <strong>first</strong> character of a line, <strong>after</strong> replacement, this time, it’s its <strong>second</strong> character which is, now, located at <strong>beginning</strong> of <strong>current</strong> line ! Therefore, as this satisfies the search regex, this <strong>second</strong> character is, then, <strong>deleted</strong>, too ! And so on…</p>
<p dir="auto">On the contrary, when your search for the <strong>first two</strong> characters and just rewrite the <strong>second</strong> one, <strong>after</strong> the replacement, <strong>current</strong> location is after this <strong>re-written</strong> character ( so, <strong>NOT</strong> at beginning of a line ! )</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/45709</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45709</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 30 Jul 2019 08:50:00 GMT</pubDate></item><item><title><![CDATA[Reply to Regex start of line doesn&#x27;t work as expected on Sun, 28 Jul 2019 13:27:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/salvatore-falcone" aria-label="Profile: Salvatore-Falcone">@<bdi>Salvatore-Falcone</bdi></a></p>
<p dir="auto">in your example, once the first char has been removed, the next char is the first again.<br />
So, I guess you are looking for something like<br />
find what:<code>^.(.*)$</code><br />
replace with <code>\1</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/45699</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/45699</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Sun, 28 Jul 2019 13:27:17 GMT</pubDate></item></channel></rss>