<?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 - Select the first 10 lines (included blank ones) in 200 files]]></title><description><![CDATA[<p dir="auto">I try a regex to select in more then 200 .txt, the first 10 lines (included blank ones). I will use Search and Replace all. I try something like this, but doesn’t work:</p>
<p dir="auto"><code>^\A(.*\n){10}</code></p>
]]></description><link>https://community.notepad-plus-plus.org/topic/13011/regex-select-the-first-10-lines-included-blank-ones-in-200-files</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 04:41:14 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/13011.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 31 Dec 2016 13:58:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex - Select the first 10 lines (included blank ones) in 200 files on Sun, 01 Jan 2017 09:12:49 GMT]]></title><description><![CDATA[<p dir="auto"><code>(?:^.*\R?){10}\z</code></p>
<p dir="auto">WORKS  ! Thanks</p>
]]></description><link>https://community.notepad-plus-plus.org/post/20462</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/20462</guid><dc:creator><![CDATA[Vasile Caraus]]></dc:creator><pubDate>Sun, 01 Jan 2017 09:12:49 GMT</pubDate></item><item><title><![CDATA[Reply to Regex - Select the first 10 lines (included blank ones) in 200 files on Sun, 01 Jan 2017 09:01:57 GMT]]></title><description><![CDATA[<p dir="auto"><strong>Vasile</strong>, and <strong>All</strong>,</p>
<p dir="auto">Ah yes ! I suppose that you tested my regex against a file, whose the <strong>last</strong> line doest <strong>not</strong> end with a <strong>line break</strong> ! We have to <strong>slightly</strong> change the regex by adding an <strong><code>?</code></strong> after <strong><code>\R</code></strong></p>
<p dir="auto">So, the <strong>final</strong> general regex to <strong>delete</strong> the <strong>Nth last</strong> lines, of a file, should be <strong><code>(?:^.*\R?){N}\z</code></strong> :-)) Just replace le <strong>upper-case</strong> letter <strong>N</strong> by the suitable integer !</p>
<p dir="auto">It gives me the opportunity to wish you, and all people of the <strong>N++ Community</strong>, a very <strong>Happy New Year 2017</strong> !</p>
<p dir="auto">Although, the very recent events , in <strong>Turkey</strong>, means that <strong>2017</strong> is not going to be <strong>better</strong> than <strong>2016</strong> :-(( What an insult to <strong>Intelligence</strong> and <strong>Wisdom</strong> !</p>
<p dir="auto">Cheers</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/20461</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/20461</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 01 Jan 2017 09:01:57 GMT</pubDate></item><item><title><![CDATA[Reply to Regex - Select the first 10 lines (included blank ones) in 200 files on Sun, 01 Jan 2017 08:20:14 GMT]]></title><description><![CDATA[<p dir="auto">your last regex , to delete the last 10 line <code>(?:^.*\R){10}\z</code> doesn’t work at my place.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/20458</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/20458</guid><dc:creator><![CDATA[Vasile Caraus]]></dc:creator><pubDate>Sun, 01 Jan 2017 08:20:14 GMT</pubDate></item><item><title><![CDATA[Reply to Regex - Select the first 10 lines (included blank ones) in 200 files on Sat, 31 Dec 2016 22:40:26 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <strong>Vasile</strong>,</p>
<p dir="auto">I already thought about this <strong>nice</strong> solution : To catch all the contents of the file and, with <strong>parentheses</strong> grouping, split these contents in <strong>two</strong> parts the <strong>first ten</strong> lines, in one part and the <strong>remainder</strong> of the file,  as the other part</p>
<p dir="auto">I didn’t speak about this <strong>solution</strong> for <strong>two</strong> reasons :</p>
<ul>
<li>
<p dir="auto">Firstly, you didn’t say, in your <strong>previous</strong> post, what you wanted to do, exactly, about theses <strong>10</strong> lines, through your <strong>200</strong> files</p>
</li>
<li>
<p dir="auto">Secondly, I didn’t know the <strong>medium size</strong> of your files, and, as the <strong>group 1</strong> must <strong>catch</strong>, practically, <strong>all</strong> the contents of each file, I suppose that it would be a <strong>problem</strong> to apply such a regex on a <strong>very big</strong> file !?</p>
</li>
</ul>
<p dir="auto">My regex version, which gives the <strong>same</strong> result, would be :</p>
<p dir="auto">SEARCH <strong><code>\A(?-s)(?:^.*\R){10}(?s)(.*)</code></strong></p>
<p dir="auto">REPLACE <strong><code>\1</code></strong></p>
<p dir="auto">I just <strong>added</strong>, the part <strong><code>(?s)(.*)</code></strong>, which stores <strong>any</strong> text, <strong>after</strong> the <strong>first ten</strong> lines, in <strong>group 1</strong></p>
<p dir="auto">These <strong>new</strong> regexes certainly work fine, when using the <strong>Find in Files</strong> feature. However, for a <strong>single</strong> file, be aware about the behaviour of <strong>my</strong> regex and <strong>your</strong> regex :</p>
<ul>
<li>
<p dir="auto">If you <strong>redo</strong> the S/R, it just deletes the <strong>next</strong> other block of <strong>ten</strong> lines ! ( So the initial lines from <strong>11</strong> to <strong>20</strong> ) Quite normal, as the <strong>very beginning</strong> of the file has changed !</p>
</li>
<li>
<p dir="auto">If you move the <strong>caret</strong> at <strong>beginning</strong> of a line, let’s say, in the <strong>middle</strong> of the file, it will, simply, delete the <strong>next ten</strong> lines, too !</p>
</li>
</ul>
<hr />
<p dir="auto">For deleting the <strong>last ten</strong> lines of a file, I propose :</p>
<p dir="auto">SEARCH <strong><code>(?:^.*\R){10}\z</code></strong></p>
<p dir="auto">REPLACE <strong><code>Empty</code></strong></p>
<p dir="auto">Of course, as the <strong>forward</strong> assertions, like <strong><code>\z</code></strong> are not <strong>bugged</strong>, the regex is <strong>more</strong> simple :-))</p>
<p dir="auto">BTW, your regex, for deleting the <strong>last</strong> lines of a file, seems to delete <strong>9</strong> lines, only !</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/20448</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/20448</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 31 Dec 2016 22:40:26 GMT</pubDate></item><item><title><![CDATA[Reply to Regex - Select the first 10 lines (included blank ones) in 200 files on Sat, 31 Dec 2016 21:06:06 GMT]]></title><description><![CDATA[<p dir="auto">hello guy38. Happy new year…almost !!</p>
<p dir="auto">So, your regex are good…but doesn’t work to well on Replace All. Practically will replace 10 by 10 lines, until the end of file, and this will delete all the file.</p>
<p dir="auto">But, I find a very good answer at the internet, the best answer:</p>
<p dir="auto">Remove the first 10 lines, but you will need to match the whole document text but only capure lines from 11 to the end.</p>
<p dir="auto">Find: <code>\A.*(?:\R.*){9}\R?([\s\S]*)</code><br />
Replace: <code>$1</code></p>
<p dir="auto">To remove the last 10 lines:</p>
<p dir="auto">Find: <code>^.*(?:\R.*){9}\z</code><br />
Replace: <code>empty</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/20447</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/20447</guid><dc:creator><![CDATA[Vasile Caraus]]></dc:creator><pubDate>Sat, 31 Dec 2016 21:06:06 GMT</pubDate></item><item><title><![CDATA[Reply to Regex - Select the first 10 lines (included blank ones) in 200 files on Sat, 31 Dec 2016 18:12:20 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <strong>vasile</strong>,</p>
<p dir="auto">Are your 200 files be <strong>Windows</strong> files with <strong><code>CR LF</code></strong> <strong>line break</strong> or only <strong><code>LF</code></strong> like in <strong>Unix</strong> files ?</p>
<p dir="auto">If you’re using the <strong>default Windows</strong> End of Line, I think that a <strong>correct</strong> regex would be <strong><code>\A(?-s)(?:^.*\R){10}</code></strong></p>
<p dir="auto">I just used a <strong>non-capturing</strong> group as I supposed that the contents of the <strong>tenth</strong> line are not needed ! If you need to re-use all its <strong>ten-lines</strong> block, in replacement, just surround it with <strong>parentheses</strong> : <strong><code>\A(?-s)((?:^.*\R){10})</code></strong></p>
<p dir="auto">BEWARE : Due to the <strong>very bad</strong> handling of the <strong>backward assertions</strong>, by our <strong>present Boost</strong> regex engine, this regex, <strong>WRONGLY</strong>, matches <strong>all</strong> the <strong>10</strong> lines-blocks, of the current file, instead of matching the <strong>first 10</strong> lines of the file, ONLY :-((</p>
<p dir="auto">I tried to find out an <strong>equivalent</strong> regex, which would <strong>not</strong> use the <strong><code>\A</code></strong> syntax, but this is just impossible !</p>
<p dir="auto">So, <strong>unfortunately</strong>, the remaining solutions are :</p>
<ul>
<li>
<p dir="auto">Use the <strong>François-R Boyer</strong> regex engine with a N++ version <strong>&lt;= 6.9</strong>, which correctly handle <strong>backwards assertions</strong></p>
</li>
<li>
<p dir="auto">Use a <strong>Lua</strong> or <strong>Python</strong> script ( Moreover, I know that the <strong>Python</strong> regex engine, correctly, support the <strong><code>\A</code></strong> assertion )</p>
</li>
<li>
<p dir="auto">Create a N++ <strong>macro</strong>, to select the <strong>first ten</strong> lines of each file</p>
</li>
</ul>
<p dir="auto">Best Regards</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/20444</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/20444</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 31 Dec 2016 18:12:20 GMT</pubDate></item></channel></rss>