<?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[How to insert text into the second line with RegEx in Notepad ++ ?]]></title><description><![CDATA[<p dir="auto">I have a list of txt files under a directory.<br />
I wish to insert a fixed block of text into each of the txt files, but only add into the second line; and the original second line content will automatically become the third line.</p>
<p dir="auto">Example:<br />
Original:</p>
<p dir="auto">This is my original first line.<br />
This is my original second line.<br />
This is my original third line.</p>
<p dir="auto">After RegEx operation, the content becomes</p>
<p dir="auto">This is my original first line.<br />
This is my inserted content, it becomes the second line.<br />
This is my original second line.<br />
This is my original third line.</p>
<p dir="auto">Thank you in advance!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/19748/how-to-insert-text-into-the-second-line-with-regex-in-notepad</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 15:46:30 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/19748.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 21 Jul 2020 18:26:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Thu, 23 Jul 2020 12:47:38 GMT]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1595508450220-schowek01.jpg" alt="Schowek01.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/56192</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56192</guid><dc:creator><![CDATA[Thomas 2020]]></dc:creator><pubDate>Thu, 23 Jul 2020 12:47:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Thu, 23 Jul 2020 10:24:36 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/nz-select" aria-label="Profile: nz-select">@<bdi>nz-select</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: ekopalypse">@<bdi>ekopalypse</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-R">@<bdi>terry-R</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/pan-jan" aria-label="Profile: pan-jan">@<bdi>pan-jan</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, we saw in some <strong>previous</strong> discussions that the <strong><code>\A</code></strong> assertion, representing the <strong>zero-length</strong> location of the <strong>very beginning</strong> of current file, isn’t <strong>properly</strong> handled in the N++ <strong>regex</strong> engine</p>
<p dir="auto">After some tests, we improved the <strong>good</strong> behavior of this assertion by changing the <strong><code>\A</code></strong> syntax with the <strong>new</strong> form <strong><code>\A^</code></strong> ( or some <strong>similar</strong> ones )</p>
<p dir="auto">However, there were still of lot of <strong>problems</strong>, when files began with some <strong>empty</strong> lines and/or when the <strong>replacement</strong> part ended with <strong>line-break</strong> characters</p>
<p dir="auto">Thus :</p>
<ul>
<li>
<p dir="auto">The <strong>first</strong> solution is to use the <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> solution, which matches the <strong>entire</strong> contents of each <strong>scanned</strong> file and works <strong>perfectly</strong> for usual files However, the regex behavior may be problematic when <strong>very big</strong> files are concerned ! Luckily, to give you an idea, it <strong>correctly</strong> inserted a block of <strong><code>3</code></strong> lines <strong>after</strong> the <strong>first</strong> lines of a file containing <strong><code>100,000</code></strong> lines about ;-))</p>
</li>
<li>
<p dir="auto">The <strong>second</strong> solution is to use the <strong>new</strong> regexes S/R, below, which solve all <strong>normal</strong> cases and most of these <strong>edge-cases</strong> and do <strong>not</strong> mind about file <strong>size</strong> !</p>
</li>
</ul>
<hr />
<ul>
<li>
<p dir="auto">So, here is the <strong>generic</strong> regex S/R which insert a <strong>block</strong> of <strong><code>M</code></strong> lines <strong>after</strong> the <strong>first</strong> <strong><code>N</code></strong> ( <strong><code>N &gt; 0</code></strong> ) lines, <strong>empty</strong> or <strong>not</strong>, of <strong>current</strong> file :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?-s)\A^(?:.*\R){</code>N-1<code>}.*\K(?=(\R))</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>\1New_Line_1\1New_Line_2\1New_Line_3</code></strong></p>
</li>
</ul>
</li>
</ul>
<p dir="auto">Of course, change the value <strong><code>N-1</code></strong> value by the <strong>appropriate</strong> integer !</p>
<ul>
<li>
<p dir="auto">From this <strong>generic</strong> regex, it’s easy to deduce the <strong>search</strong> regex for some <strong>small</strong> values of <strong>N</strong>  ( <strong>same</strong> replacement regex ) :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?-s)\A^.*\K(?=(\R))</code></strong>    ( Case <strong>N</strong> = <strong><code>1</code></strong> =&gt; Insertion <strong>after</strong> the <strong><code>first</code></strong> line )</p>
</li>
<li>
<p dir="auto">SEARCH <strong><code>(?-s)\A^.*\R.*\K(?=(\R))</code></strong>   ( Case <strong>N</strong> = <strong><code>2</code></strong> =&gt; Insertion <strong>after</strong> the <strong><code>second</code></strong> line )</p>
</li>
</ul>
</li>
</ul>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">In the <strong>generic</strong> regex above, the value <strong>N</strong> must be strictly <strong>positive</strong>, in order that <strong>N-1</strong> &gt;= <strong><code>0</code></strong></p>
</li>
<li>
<p dir="auto">These different regexes, above, work <strong>whatever</strong> the <strong>type</strong> of files ( <strong><code>Windows</code></strong>, <strong><code>Unix</code></strong> or <strong><code>Mac</code></strong> ). Current <strong>line-break</strong> is stored as <strong>group <code>1</code></strong> and is rewritten, in the <strong>replacement</strong> regex, with the syntax <strong><code>\1</code></strong></p>
</li>
<li>
<p dir="auto">If you omit the <strong>first</strong> <strong><code>\1</code></strong> syntax, in <strong>replacement</strong>, you may join the <strong>first</strong> <strong><code>Nth</code></strong> initial line, <strong>right after</strong> the <strong>inserted</strong> block of <strong><code>M</code></strong> lines !</p>
</li>
</ul>
<p dir="auto">One example : assuming this <strong>sample</strong> text :</p>
<pre><code class="language-diff">First initial line
Second initial line
Third initial line
Fourth initial line
Fifth initial line
Sixth initial line
Seventh initial line
Eighth initial line
Ninth initial line
Tenth initial line 
</code></pre>
<p dir="auto">The <strong>regex</strong> S/R :</p>
<p dir="auto">SEARCH <strong><code>(?-s)\A^(?:.*\R){5}.*\K(?=(\R))</code></strong>    Insertion <strong>after</strong> <strong><code>6th</code></strong> line means that <strong><code>{</code>N- 1<code>}</code></strong> = <strong><code>{5}</code></strong></p>
<p dir="auto">REPLACE <strong><code>\1New_Line_1\1New_Line_2\1New_Line_3</code></strong></p>
<p dir="auto">would return :</p>
<pre><code class="language-diff">First initial line
Second initial line
Third initial line
Fourth initial line
Fifth initial line
Sixth initial line
New_Line_1
New_Line_2
New_Line_3
Seventh initial line
Eighth initial line
Ninth initial line
Tenth initial line 
</code></pre>
<hr />
<ul>
<li>
<p dir="auto">In case of an insertion <strong>before</strong> the <strong><code>first</code></strong> <strong>NON-empty</strong> line, use the following <strong>regex</strong> S/R :</p>
<ul>
<li>
<p dir="auto">SEARCH <strong><code>(?-s)\A^\R*\K(?=.*(\R))</code></strong></p>
</li>
<li>
<p dir="auto">REPLACE <strong><code>New_Line_1\1New_Line_2\1New_Line_3\1</code></strong></p>
</li>
</ul>
</li>
</ul>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">As before, this regex S/R works <strong>whatever</strong> the <strong>type</strong> of files ( <strong><code>Windows</code></strong>, <strong><code>Unix</code></strong> or <strong><code>Mac</code></strong> ). Current <strong>line-break</strong> is stored as <strong>group <code>1</code></strong> and is rewritten, in the <strong>replacement</strong> regex, with the syntax <strong><code>\1</code></strong></p>
</li>
<li>
<p dir="auto">If you omit the <strong>last</strong> <strong><code>\1</code></strong> syntax, in <strong>replacement</strong>, you may join the <strong><code>first</code></strong> <strong>non-empty</strong> line, <strong>right after</strong> the <strong>inserted</strong> block of <strong><code>M</code></strong> lines !</p>
</li>
</ul>
<hr />
<p dir="auto">Now, note that in order to <strong>insert</strong> a block of lines <strong>before</strong> the <strong><code>first</code></strong> <strong>empty</strong> line, we need to use the <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> <strong>flavor</strong>, which matches the <strong>integrity</strong> of current file, at once. So, the following regex will <strong>insert</strong> a block <strong><code>M</code></strong> lines <strong>before</strong> the <strong><code>first</code></strong> line , <strong>empty</strong> or <strong>not</strong> :</p>
<p dir="auto">SEARCH <strong><code>(?-s)\A^\K(.*(\R)(?s).*)</code></strong></p>
<p dir="auto">REPLACE <strong><code>New_Line_1\2New_Line_2\2New_Line_3\2\1</code></strong></p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">As before, this regex S/R works <strong>whatever</strong> the <strong>type</strong> of files ( <strong><code>Windows</code></strong>, <strong><code>Unix</code></strong> or <strong><code>Mac</code></strong> ). Current <strong>line-break</strong> is stored as <strong>group <code>2</code></strong> and is rewritten, in the <strong>replacement</strong> regex, with the syntax <strong><code>\2</code></strong></p>
</li>
<li>
<p dir="auto">If you omit the <strong>last</strong> <strong><code>\2</code></strong> syntax, in <strong>replacement</strong>, you may join the <strong><code>first</code></strong> line, <strong>empty</strong> or <strong>not</strong>, <strong>right after</strong> the <strong>inserted</strong> block of <strong><code>M</code></strong> lines !</p>
</li>
<li>
<p dir="auto">Note that <strong>all</strong> the contents of <strong>current</strong> file are stored as <strong>group <code>1</code></strong></p>
</li>
<li>
<p dir="auto">As said before, you may get some <strong>issues</strong> when executed against files of <strong>very important</strong> size !</p>
</li>
</ul>
<hr />
<p dir="auto">Of course, the <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> regex <strong>flavor</strong> can be <strong>generalized</strong> ! So, the following regex S/R will <strong>insert</strong> any block of <strong><code>M</code></strong> lines <strong>after</strong> the <strong>first</strong> <strong><code>N</code></strong> ( <strong>N</strong> &gt;= <strong><code>0</code></strong> ) lines, <strong>empty</strong> or <strong>not</strong>, of <strong>current</strong> file :</p>
<p dir="auto">SEARCH <strong><code>(?-s)\A^(?:.*\R){</code>N<code>}\K(.*(\R)(?s).*)</code></strong></p>
<p dir="auto">REPLACE <strong><code>New_Line_1\2New_Line_2\2New_Line_3\2\1</code></strong></p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">Of course, if <strong>N</strong> = <strong><code>0</code></strong>, this would mean insertion after line <strong><code>0</code></strong>, so, practically, insertion <strong>before</strong> the <strong><code>first</code></strong> line, <strong>empty</strong> or <strong>not</strong> !</p>
</li>
<li>
<p dir="auto">As before, this regex S/R works <strong>whatever</strong> the <strong>type</strong> of files ( <strong><code>Windows</code></strong>, <strong><code>Unix</code></strong> or <strong><code>Mac</code></strong> ). Current <strong>line-break</strong> is stored as <strong>group <code>2</code></strong> and is rewritten, in the replacement regex, with the syntax <strong><code>\2</code></strong></p>
</li>
<li>
<p dir="auto">After the <strong>first</strong> <strong><code>N</code></strong> lines, the <strong>remaining</strong> contents of <strong>current</strong> file are stored as <strong>group <code>1</code></strong></p>
</li>
<li>
<p dir="auto">If you omit the <strong>last</strong> <strong><code>\2</code></strong> syntax, in <strong>replacement</strong>, you may join the <strong>first</strong> <strong><code>Nth</code></strong> line, <strong>empty</strong> or <strong>not</strong>, <strong>right after</strong> the <strong>inserted</strong> block of <strong><code>M</code></strong> lines !</p>
</li>
<li>
<p dir="auto">As said before, you may get some <strong>issues</strong> when executed against files of <strong>very important</strong> size !</p>
</li>
</ul>
<hr />
<p dir="auto">Assuming the <strong>same</strong> example as before, the <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> " <strong>flavor</strong> " regex S/R :</p>
<p dir="auto">SEARCH <strong><code>(?-s)\A^(?:.*\R){6}\K(.*(\R)(?s).*)</code></strong></p>
<p dir="auto">REPLACE <strong><code>New_Line_1\2New_Line_2\2New_Line_3\2\1</code></strong></p>
<p dir="auto">would give the <strong>same</strong> output text :</p>
<pre><code class="language-diff">First initial line
Second initial line
Third initial line
Fourth initial line
Fifth initial line
Sixth initial line
New_Line_1
New_Line_2
New_Line_3
Seventh initial line
Eighth initial line
Ninth initial line
Tenth initial line 
</code></pre>
<p dir="auto">Best regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56185</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56185</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 23 Jul 2020 10:24:36 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 11:27:04 GMT]]></title><description><![CDATA[<p dir="auto">NZ Select;<br />
This code works perfectly:</p>
<p dir="auto">Search<br />
(?-s)^((.+)?\R)(?s)(.+)*<br />
Replace<br />
Replace With:\1New Line 2\r\n\3<br />
++++++++++++++++++++++++++++<br />
You can give an example where this will work,<br />
(?-s)^((.+)?\R)(?s)(.+)*<br />
\1New Line 2\r\n\3</p>
<p dir="auto">and this one will not work anymore?<br />
\n^(.+)<br />
txt\n\1</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56180</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56180</guid><dc:creator><![CDATA[Thomas 2020]]></dc:creator><pubDate>Wed, 22 Jul 2020 11:27:04 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 07:49:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nz-select" aria-label="Profile: NZ-Select">@<bdi>NZ-Select</bdi></a> said in <a href="/post/56173">How to insert text into the second line with RegEx in Notepad ++ ?</a>:</p>
<blockquote>
<p dir="auto">I don’t understand how exactly it is creating this magic</p>
</blockquote>
<p dir="auto">The magic as you mention is having the regex cover the whole file in 1 cycle, instead of what normally happens when a regex completes several cycles by the time the complete file has been processed. That means my regex can ONLY replace/insert characters once.</p>
<p dir="auto">The first part grabs 1 line ONLY as the (?-s) does NOT allow the <code>.</code> to include end of line characters (carriage return and line feed). This is saved as group 1. Group 2 captures the rest of the file as the (?s) allows the <code>.</code> to include end of line characters.<br />
The “replace with” command writes back groups 1 and 2, but with the inserted lines between them. The <code>\r\\n</code> are the carriage return and line feed characters.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56175</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56175</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Wed, 22 Jul 2020 07:49:16 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 07:26:54 GMT]]></title><description><![CDATA[<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></p>
<p dir="auto">Thank you.</p>
<p dir="auto">I don’t understand how exactly it is creating this magic.<br />
I am putting the code here, it does give a little hint on what function each magic tiny code is doing.<br />
<a href="https://regex101.com/" rel="nofollow ugc">https://regex101.com/</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/56173</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56173</guid><dc:creator><![CDATA[NZ Select]]></dc:creator><pubDate>Wed, 22 Jul 2020 07:26:54 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 07:23:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pan-jan" aria-label="Profile: Pan-Jan">@<bdi>Pan-Jan</bdi></a> said in <a href="/post/56168">How to insert text into the second line with RegEx in Notepad ++ ?</a>:</p>
<blockquote>
<p dir="auto">txt\n$1</p>
</blockquote>
<p dir="auto">I tried the code above, it will insert “txt” to line number 2; if only run once.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56172</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56172</guid><dc:creator><![CDATA[NZ Select]]></dc:creator><pubDate>Wed, 22 Jul 2020 07:23:58 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 06:11:23 GMT]]></title><description><![CDATA[<p dir="auto">It works for me.<br />
\n^(.+)<br />
txt\n$1</p>
<p dir="auto">My motto:<br />
The simpler the pattern, the better.<br />
<img src="/assets/uploads/files/1595398174568-schowek01.jpg" alt="Schowek01.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/56168</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56168</guid><dc:creator><![CDATA[Thomas 2020]]></dc:creator><pubDate>Wed, 22 Jul 2020 06:11:23 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 03:21:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nz-select" aria-label="Profile: NZ-Select">@<bdi>NZ-Select</bdi></a> said in <a href="/post/56166">How to insert text into the second line with RegEx in Notepad ++ ?</a>:</p>
<blockquote>
<p dir="auto">if there are three lines to be inserted at once</p>
</blockquote>
<p dir="auto">Replace the current "Replace With field with<br />
<code>\1New Line 2\r\nNew Line 3\r\nNew Line 4\r\n\3</code><br />
Obviously each of the New Line 2, New Line 3 and New Line 4 would be your inserted lines.<br />
Alternatively you could run the regex 3 times, first with the 3rd line to be inserted, then the 2nd line and finally by the 1st inserted line. They should appear in the correct order.</p>
<p dir="auto">Did you understand what the regex is doing or do you want a bit of an explanation to better understand what it is doing?</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56167</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56167</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Wed, 22 Jul 2020 03:21:31 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 03:14:51 GMT]]></title><description><![CDATA[<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></p>
<p dir="auto">Hi Terry,</p>
<p dir="auto">I tried the code it works fine.</p>
<p dir="auto">The replacing code is</p>
<pre><code>\1New Line 2\r\n\3
</code></pre>
<p dir="auto">May I know if there are three lines to be inserted at once, how shall I keep the value of the three lines?</p>
<p dir="auto">I mean it is like</p>
<p dir="auto">This is my original first line.<br />
This is my original second line.<br />
This is my original third line.</p>
<p dir="auto">To be inserted to the second line position:<br />
Insert sentense 1<br />
Insert sentense 2<br />
Insert sentense 3</p>
<p dir="auto">I tried the following code:</p>
<pre><code>\1Insert sentense 1
Insert sentense 2
Insert sentense 3\r\n\3
</code></pre>
<p dir="auto">I found the above code will break the replacing function.</p>
<pre><code>\1Insert sentense 1. \n Insert sentense 2 \n Insert sentense 3\r\n\3
</code></pre>
<p dir="auto">The above code will work when inserting a paragraph.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56166</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56166</guid><dc:creator><![CDATA[NZ Select]]></dc:creator><pubDate>Wed, 22 Jul 2020 03:14:51 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 02:31:24 GMT]]></title><description><![CDATA[<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 in <a href="/post/56155">How to insert text into the second line with RegEx in Notepad ++ ?</a>:</p>
<blockquote>
<p dir="auto">\1New Line 2\r\n\3</p>
</blockquote>
<p dir="auto">Hi Terry,</p>
<p dir="auto">This code works perfectly:</p>
<p dir="auto">Search<br />
(?-s)^((.+)?\R)(?s)(.+)*<br />
Replace<br />
Replace With:\1New Line 2\r\n\3</p>
<p dir="auto">My notes:<br />
There is a 1 before the intended insert text.</p>
<p dir="auto">P.s I do not need to open my files first.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56164</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56164</guid><dc:creator><![CDATA[NZ Select]]></dc:creator><pubDate>Wed, 22 Jul 2020 02:31:24 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Wed, 22 Jul 2020 02:15:01 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><br />
Thank you!<br />
Each file will begin with non-empty line.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56163</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56163</guid><dc:creator><![CDATA[NZ Select]]></dc:creator><pubDate>Wed, 22 Jul 2020 02:15:01 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 23:01:24 GMT]]></title><description><![CDATA[<p dir="auto">I didn’t understand there were more open files.<br />
I’ll work on that later.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56159</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56159</guid><dc:creator><![CDATA[Thomas 2020]]></dc:creator><pubDate>Tue, 21 Jul 2020 23:01:24 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 22:42:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pan-jan" aria-label="Profile: Pan-Jan">@<bdi>Pan-Jan</bdi></a></p>
<p dir="auto">I think you missed the point. The file won’t already be open in NPP, instead you’d use the “Find in Files” tab that you can see in your images. This allows you to work on <code>MANY</code> files at once using the same regex that you would on a single file opened in NPP. In that tab the button is “Replace in Files” which I believe is equivalent to a “Replace All” if used on an opened file.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56156</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56156</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Tue, 21 Jul 2020 22:42:36 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 22:38:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nz-select" aria-label="Profile: NZ-Select">@<bdi>NZ-Select</bdi></a> said in <a href="/post/56137">How to insert text into the second line with RegEx in Notepad ++ ?</a>:</p>
<blockquote>
<p dir="auto">but only add into the second line</p>
</blockquote>
<p dir="auto">It seemed to be a relatively easy problem to solve, however it wasn’t. I’ll reference a conversation I was involved in about a year ago on the very issue of how to reference the start of a file:<br />
<a href="https://community.notepad-plus-plus.org/topic/15998/regex-anchor-for-beginning-of-file?_=1595369289169">https://community.notepad-plus-plus.org/topic/15998/regex-anchor-for-beginning-of-file?_=1595369289169</a></p>
<p dir="auto">The use of <code>\A</code> and indeed my suggested replacement does not work in this instance. Back then we didn’t consider the “Find in Files” function, only opened files within Notepad++. Maybe <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> will be able to come up with a guaranteed solution and possibly even a reason behind the failure of the options presented in that conversation. Until then I have a solution which “appears” to work, even on a file of around 6MB, and 90K plus lines.</p>
<p dir="auto">So using the “Find in Files” function, you’d insert the appropriate filters, directory and tick if sub-folders were to be included. Search mode is obviously “regular expression”. The regex is:<br />
Find What:<code>(?-s)^((.+)?\R)(?s)(.+)*</code><br />
Replace With:<code>\1New Line 2\r\n\3</code><br />
You need to replace <code>New Line 2</code> (in the Replace With field) with your line to be inserted. If any of the characters to be inserted are “meta-characters” (such as ^$*?(){}[] and others) you will need to precede them with the “escape” key <code>\</code>.<br />
Click the “Find in Files” button and OK the query that appears (are you sure?).</p>
<p dir="auto">As always, it pays to have a backup copy of the files before running the first time and to verify some randomly.</p>
<p dir="auto">Good luck<br />
Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56155</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56155</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Tue, 21 Jul 2020 22:38:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 22:36:22 GMT]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1595370958701-schowek00.jpg" alt="Schowek00.jpg" class=" img-fluid img-markdown" /><br />
<img src="/assets/uploads/files/1595370966707-schowek01.jpg" alt="Schowek01.jpg" class=" img-fluid img-markdown" /><br />
<img src="/assets/uploads/files/1595370977420-schowek02.jpg" alt="Schowek02.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/56154</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56154</guid><dc:creator><![CDATA[Thomas 2020]]></dc:creator><pubDate>Tue, 21 Jul 2020 22:36:22 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 20:32:05 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/nz-select" aria-label="Profile: nz-select">@<bdi>nz-select</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/pan-jan" aria-label="Profile: pan-jan">@<bdi>pan-jan</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: ekopalypse">@<bdi>ekopalypse</bdi></a> and <strong>All</strong>,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nz-select" aria-label="Profile: nz-select">@<bdi>nz-select</bdi></a>, one question :</p>
<ul>
<li>Do some of your files begin with <strong>true empty</strong> lines file OR <strong>each</strong> file begins with a <strong>non-empty</strong> line ?</li>
</ul>
<p dir="auto">See you later,</p>
<p dir="auto">Best Regards</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56153</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56153</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 21 Jul 2020 20:32:05 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 20:00:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pan-jan" aria-label="Profile: Pan-Jan">@<bdi>Pan-Jan</bdi></a></p>
<p dir="auto">but the OP looks for a replacement in multiple files.<br />
Not sure OP likes to open each file first. Could be hundreds of it.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56149</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56149</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 21 Jul 2020 20:00:08 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 19:53:28 GMT]]></title><description><![CDATA[<p dir="auto"><img src="/assets/uploads/files/1595361023565-schowek01.jpg" alt="Schowek01.jpg" class=" img-fluid img-markdown" /><br />
it is supposed to look like this</p>
<ol>
<li>you click find</li>
<li>you click replace</li>
</ol>
<p dir="auto">and that’s all</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56148</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56148</guid><dc:creator><![CDATA[Thomas 2020]]></dc:creator><pubDate>Tue, 21 Jul 2020 19:53:28 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 19:31:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pan-jan" aria-label="Profile: Pan-Jan">@<bdi>Pan-Jan</bdi></a><br />
No, does not work.<br />
It will insert the new text multiple times.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56146</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56146</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 21 Jul 2020 19:31:12 GMT</pubDate></item><item><title><![CDATA[Reply to How to insert text into the second line with RegEx in Notepad ++ ? on Tue, 21 Jul 2020 19:18:45 GMT]]></title><description><![CDATA[<p dir="auto">Find: (\n^(.+)$)<br />
Replace: inserted line$1</p>
]]></description><link>https://community.notepad-plus-plus.org/post/56143</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/56143</guid><dc:creator><![CDATA[Thomas 2020]]></dc:creator><pubDate>Tue, 21 Jul 2020 19:18:45 GMT</pubDate></item></channel></rss>