<?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[A RegEx question - How to remove a line, including the \r\n? Thanx,]]></title><description><![CDATA[<p dir="auto">A RegEx question - How to remove a line, including the \r\n? Thanx,</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/21434/a-regex-question-how-to-remove-a-line-including-the-r-n-thanx</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 07:07:59 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/21434.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 Jul 2021 14:13:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to A RegEx question - How to remove a line, including the \r\n? Thanx, on Sat, 03 Jul 2021 23:43:07 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> Thanx a bunch. Much appreciated</p>
]]></description><link>https://community.notepad-plus-plus.org/post/67663</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/67663</guid><dc:creator><![CDATA[bob_diebel]]></dc:creator><pubDate>Sat, 03 Jul 2021 23:43:07 GMT</pubDate></item><item><title><![CDATA[Reply to A RegEx question - How to remove a line, including the \r\n? Thanx, on Fri, 02 Jul 2021 15:09:50 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/67625">A RegEx question - How to remove a line, including the \r\n? Thanx,</a>:</p>
<blockquote>
<p dir="auto">“a line”, “all the lines”, what’s the difference? 😉</p>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bob_diebel" aria-label="Profile: bob_diebel">@<bdi>bob_diebel</bdi></a> ,<br />
In case you didn’t know, the <code>(?-s)</code> that <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> added makes sure that the regex ignores the state of <code>. matches newline</code>, and instead forces the regex to have <code>.</code> <em>not</em> match newline.  Mine would have worked if <code>. matches newline</code> is off, but will match from the beginning to end of the file if <code>. matches newline</code> was on.  We regular Forum contributors try (but often fail) to use <code>(?-s)</code> or <code>(?s)</code> so that our answers will work no matter what the setting of <code>. matches newline</code>.  But since the <code>.*</code> is rather permissive anyway, a REPLACE ALL would have deleted the whole file no matter what the setting of <code>. matches newline</code>.</p>
<p dir="auto">Some more caveats: the regex will match <em>any</em> line with zero or more characters followed by the CRLF newline sequence.</p>
<ul>
<li>My guess is that you really wanted to match some specific line.  You will need a regular expression between the <code>^</code> (start of line) and <code>\r\n</code> (CRLF) that matches only the line(s) that you want to delete: <code>(?-s)^☒\r\n</code>, where I use <code>☒</code> as a placeholder for your regular expression to match the particular line(s).</li>
<li>If one of the lines you want to delete might be at the end of the file and <em>not</em> have a newline, you might need to use something like
<ul>
<li><code>(?-s)^☒(\r\n|\z)</code> – the parentheses make a group, and the <code>|</code> says “OR”, and the <code>\z</code> says “end of file”.  (same <code>☒</code> notation).  But this still has the “feature” that it will leave a final newline (so you might consider it an “empty line”) when the last matched line is the last line with no newline.</li>
<li>If you want to also delete the last newline, you could use <code>(?-s)^☒\r\n|\r\n☒\z</code> – which says to grab the whole line including CRLF if there’s a CRLF afterward, or grab the previous newline through the end-of-file if the line doesn’t end in CRLF.  This will make sure there is no “empty line” at the end of the file.</li>
</ul>
</li>
<li>Another option is to use the <strong>Search &gt; Mark</strong> dialog with teh “bookmark line” option checked, to mark all the lines; then use <strong>Search &gt; Bookmark &gt; Remove Bookmarked Lines</strong> to delete the lines.</li>
</ul>
]]></description><link>https://community.notepad-plus-plus.org/post/67626</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/67626</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 02 Jul 2021 15:09:50 GMT</pubDate></item><item><title><![CDATA[Reply to A RegEx question - How to remove a line, including the \r\n? Thanx, on Fri, 02 Jul 2021 14:51:25 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 in <a href="/post/67624">A RegEx question - How to remove a line, including the \r\n? Thanx,</a>:</p>
<blockquote>
<p dir="auto">for maximum safety.</p>
</blockquote>
<p dir="auto">“a line”, “all the lines”, what’s the difference? 😉</p>
]]></description><link>https://community.notepad-plus-plus.org/post/67625</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/67625</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 02 Jul 2021 14:51:25 GMT</pubDate></item><item><title><![CDATA[Reply to A RegEx question - How to remove a line, including the \r\n? Thanx, on Fri, 02 Jul 2021 14:44:08 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/67623">A RegEx question - How to remove a line, including the \r\n? Thanx,</a>:</p>
<blockquote>
<p dir="auto">^.*\r\n</p>
</blockquote>
<p dir="auto">I would adjust that to be <code>(?-s)^.*\r\n</code> for maximum safety. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/67624</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/67624</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 02 Jul 2021 14:44:08 GMT</pubDate></item><item><title><![CDATA[Reply to A RegEx question - How to remove a line, including the \r\n? Thanx, on Fri, 02 Jul 2021 14:27:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bob_diebel" aria-label="Profile: bob_diebel">@<bdi>bob_diebel</bdi></a></p>
<p dir="auto">regular expression mode: FIND <code>^.*\r\n</code> REPLACE empty.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/67623</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/67623</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 02 Jul 2021 14:27:36 GMT</pubDate></item></channel></rss>