<?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[Reg Ex to find lines with linefeeds in csv]]></title><description><![CDATA[<p dir="auto">I’m working with a pipe-delimited csv. The column format is 10 columns with 9 pipes in a row and then a line feed - NOT CRLF, just LF. But there are LOTS of records that have line feeds within one or more columns in a single row. I need to replace the “interior” line feeds with a dummy/replacement string (#$%*).</p>
<p dir="auto">Some examples of valid rows (“[LF]” indicating the end of line Line Feed, of course)::</p>
<ul>
<li>lorem|1|2|1|1|1|0|||9887544[LF]</li>
<li>dolor|6|6|1|1|0|0|||123456[LF]</li>
</ul>
<p dir="auto">Examples of invalid records - they have a single column broken across multiple lines due to interior line feeds:</p>
<p dir="auto">dolor|0|3|2|0|0|0||Lorem ipsum dolor sit amet[LF]<br />
consectetur adipiscing elit[LF]<br />
sed do eiusmod tempor incididunt[LF]<br />
ut labore et dolore magna aliqua|[LF]</p>
<p dir="auto">lorem|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit,[LF]<br />
sed do eiusmod tempor incididunt[LF]<br />
ut labore et dolore magna aliqua[LF]<br />
Ut enim ad minim veniam,[LF]<br />
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.[LF]<br />
|[LF]</p>
<p dir="auto">I need a regex that will select lines 1 through 3 in the first example of an invalid record and lines 1 through 5 in the second example. There can be any number of Line Feeds within a given column in a single record.</p>
<p dir="auto">I have a regex that finds blocks of lines that have NO pipes: ^[^|]*$. That will select lines 2 and 3 in the first example and lines 2 through 4 in the second example, but I can’t figure out how to expand on that to include the first line in each record.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/18208/reg-ex-to-find-lines-with-linefeeds-in-csv</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 03:17:48 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/18208.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Sep 2019 14:08:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Sat, 19 Oct 2019 02:05:06 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-yorkovich" aria-label="Profile: mark-yorkovich">@<bdi>mark-yorkovich</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">I was <strong>away</strong> from the <strong>N++ community</strong> since more than a <strong>month</strong> ( see my post below )</p>
<p dir="auto"><a href="https://community.notepad-plus-plus.org/post/47895">https://community.notepad-plus-plus.org/post/47895</a></p>
<p dir="auto">So, <strong>Mark</strong>, my reply is quite <strong>out of date</strong>. However, just for <strong>info</strong>, here is a <strong>one-go</strong> regex, which does what you want :</p>
<p dir="auto">SEARCH <strong><code>(?-s)([^|\n]*\|){9}.*\n|\n(?!([^|\n]*\|){9}.*\n)</code></strong></p>
<p dir="auto">REPLACE <strong><code>(?1$0:LINEFEED)</code></strong></p>
<p dir="auto">It’s the <strong>equivalent</strong> regex S/R to the <strong>Alan</strong>’s one. As you just want to replace with a <strong>single dummy</strong> char, use, for instance, the following <strong>Replace</strong> zone :</p>
<p dir="auto">REPLACE <strong><code>(?1$0:#)</code></strong></p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">First, the part <strong><code>(?-s)</code></strong> forces the regex engine to consider any <strong>dot</strong> ( <strong><code>.</code></strong> ) as a <strong>single standard</strong> character ( Not an <strong>EOF</strong> one ! )</p>
</li>
<li>
<p dir="auto">Then, the <strong>search</strong> regex processes one of the <strong>two</strong> alternatives :</p>
<ul>
<li>
<p dir="auto"><strong><code>(?-s)([^|\n]*\|){9}.*\n</code></strong> which looks for <strong>entire correct</strong> lines, containing <strong><code>9</code></strong> <strong>pipe</strong> characters. In replacement, as <strong>group <code>1</code></strong> exists, the <strong>overall</strong> match ( <strong><code>$0</code></strong> ) is just re-written</p>
</li>
<li>
<p dir="auto"><strong><code>\n(?!([^|\n]*\|){9}.*\n)</code></strong> which simply searches a <strong>line-feed</strong> char, only if <strong>NOT</strong> followed with a <strong>correct</strong> record. In replacement, as <strong>group <code>1</code></strong> does <strong>not</strong> exist, the part after the <strong>colon</strong> ( <strong>LINEFEED</strong> or <strong><code>#</code></strong> ) replaces the <strong><code>\n</code></strong> character</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/47905</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/47905</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 19 Oct 2019 02:05:06 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 19:30:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-yorkovich" aria-label="Profile: Mark-Yorkovich">@<bdi>Mark-Yorkovich</bdi></a> said:</p>
<blockquote>
<p dir="auto">Thanks!</p>
</blockquote>
<p dir="auto">No problem.  It was an interesting thing to think about.  I like some minor <a href="https://www.nytimes.com/crosswords/game/mini" rel="nofollow ugc">challenges on a daily basis</a> to keep the aging little grey cells (hopefully) fine-tuned…</p>
<p dir="auto">Key to your problem was grabbing enough text such that the real line-ending [LF] could be isolated.  Once that’s done, it becomes rather trivial…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46872</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46872</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 06 Sep 2019 19:30:23 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 19:06:25 GMT]]></title><description><![CDATA[<p dir="auto">IT WORKED!  Actually I stopped at step 2, as I just need to get it to a point where each record is on a single line - the EOL character(s) don’t matter - it just needs to be able to be opened in Excel.</p>
<p dir="auto">Dude, do you realize how much time you just saved me?! :)</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46871</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46871</guid><dc:creator><![CDATA[Mark Yorkovich]]></dc:creator><pubDate>Fri, 06 Sep 2019 19:06:25 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 18:53:17 GMT]]></title><description><![CDATA[<p dir="auto">The earlier steps were made with some bogus assumptions due to not enough data.</p>
<p dir="auto">And/or just some plain old mistakes. :)</p>
<p dir="auto">So taking the new, lengthier data, which in reality is (I think) this, in a <em>Linux</em> formatted N++ tab:</p>
<pre><code>lorem62|8|5|1|1|0|0|||EQUI033
lorem62|8|6|1|1|0|0|||EQUI036
lorem62|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
consectetur adipiscing elit|
lorem-44|1|1|1|1|0|0|||3003024
lorem-44|1|2|1|1|0|0|||3001476
lorem-44|1|3|1|1|0|0|||2001415
lorem47|8|4|1|1|0|0|||EQUI032
lorem47|8|5|1|1|0|0|||EQUI033
lorem47|8|6|1|1|0|0|||EQUI036
lorem47|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit|
lorem62|1|1|1|1|0|0|||3003024
lorem62|1|2|1|1|0|0|||3001476
lorem-44|8|6|1|1|0|0|||EQUI036
lorem-44|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
consectetur adipiscing elit
|
lorem20|1|1|1|1|0|0|||3003024
lorem20|1|2|1|1|0|0|||3001476
lorem20|1|3|1|2|0|0|||3001894
lorem20|1|4|1|1|0|0|||2001443
lorem20|1|5|1|1|0|0|||2001439
lorem20|1|6|1|1|0|0|||3002274
lorem10|5|1|1|1|1|0|||MED0015
lorem20|13|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
consectetur adipiscing elit|
lorem20|3|1|1|2|0|0|||3002407
lorem16|11|0|1|0|0|0|||
</code></pre>
<p dir="auto">The following 3 replace-all transforms seem to do the job:</p>
<p dir="auto">F: <code>(?-s)^([^|]*?\|){9}.*\K\n</code><br />
R: <code>\r</code></p>
<p dir="auto">F: <code>\n</code><br />
R: <code>LINEFEED</code>  &lt;— your choice of text substitution here</p>
<p dir="auto">F: <code>\r</code><br />
R: <code>\n</code></p>
<p dir="auto">After which one obtains:</p>
<pre><code>lorem62|8|5|1|1|0|0|||EQUI033
lorem62|8|6|1|1|0|0|||EQUI036
lorem62|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elitLINEFEEDquis nostrud exercitation ullamcoLINEFEEDlaboris nisi ut aliquip ex ea commodo consequat.LINEFEEDconsectetur adipiscing elit|
lorem-44|1|1|1|1|0|0|||3003024
lorem-44|1|2|1|1|0|0|||3001476
lorem-44|1|3|1|1|0|0|||2001415
lorem47|8|4|1|1|0|0|||EQUI032
lorem47|8|5|1|1|0|0|||EQUI033
lorem47|8|6|1|1|0|0|||EQUI036
lorem47|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit|
lorem62|1|1|1|1|0|0|||3003024
lorem62|1|2|1|1|0|0|||3001476
lorem-44|8|6|1|1|0|0|||EQUI036
lorem-44|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elitLINEFEEDquis nostrud exercitation ullamcoLINEFEEDlaboris nisi ut aliquip ex ea commodo consequat.LINEFEEDconsectetur adipiscing elitLINEFEED|
lorem20|1|1|1|1|0|0|||3003024
lorem20|1|2|1|1|0|0|||3001476
lorem20|1|3|1|2|0|0|||3001894
lorem20|1|4|1|1|0|0|||2001443
lorem20|1|5|1|1|0|0|||2001439
lorem20|1|6|1|1|0|0|||3002274
lorem10|5|1|1|1|1|0|||MED0015
lorem20|13|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elitLINEFEEDquis nostrud exercitation ullamcoLINEFEEDlaboris nisi ut aliquip ex ea commodo consequat.LINEFEEDconsectetur adipiscing elit|
lorem20|3|1|1|2|0|0|||3002407
lorem16|11|0|1|0|0|0|||
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/46870</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46870</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 06 Sep 2019 18:53:17 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 18:38:32 GMT]]></title><description><![CDATA[<p dir="auto">Also, step 2 replaces the rest of the [LF] with a dummy string, resulting in 5 long lines of text, with records/lines merged.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46869</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46869</guid><dc:creator><![CDATA[Mark Yorkovich]]></dc:creator><pubDate>Fri, 06 Sep 2019 18:38:32 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 18:15:52 GMT]]></title><description><![CDATA[<p dir="auto">So, here’s a good example of what I’m working with. The multi-line records are the lines with asterisks by the line number. This forum text makes it kinda hard to read like this, but hopefully you’ll get the idea.</p>
<p dir="auto">1 lorem62|8|5|1|1|0|0|||EQUI033[LF]<br />
2 lorem62|8|6|1|1|0|0|||EQUI036[LF]<br />
*3 lorem62|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit[LF]<br />
*4 quis nostrud exercitation ullamco[LF]<br />
*5 laboris nisi ut aliquip ex ea commodo consequat.[LF]<br />
*6 consectetur adipiscing elit|[LF]<br />
7 lorem-44|1|1|1|1|0|0|||3003024[LF]<br />
8 lorem-44|1|2|1|1|0|0|||3001476[LF]<br />
9 lorem-44|1|3|1|1|0|0|||2001415[LF]<br />
10 lorem47|8|4|1|1|0|0|||EQUI032[LF]<br />
11 lorem47|8|5|1|1|0|0|||EQUI033[LF]<br />
12 lorem47|8|6|1|1|0|0|||EQUI036[LF]<br />
13 lorem47|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit|[LF]<br />
14 lorem62|1|1|1|1|0|0|||3003024[LF]<br />
15 lorem62|1|2|1|1|0|0|||3001476[LF]<br />
16 lorem-44|8|6|1|1|0|0|||EQUI036[LF]<br />
*17 lorem-44|9|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit[LF]<br />
*18 quis nostrud exercitation ullamco[LF]<br />
*19 laboris nisi ut aliquip ex ea commodo consequat.[LF]<br />
*20 consectetur adipiscing elit[LF]<br />
*21 |[LF]<br />
22 lorem20|1|1|1|1|0|0|||3003024[LF]<br />
23 lorem20|1|2|1|1|0|0|||3001476[LF]<br />
24 lorem20|1|3|1|2|0|0|||3001894[LF]<br />
25 lorem20|1|4|1|1|0|0|||2001443[LF]<br />
26 lorem20|1|5|1|1|0|0|||2001439[LF]<br />
27 lorem20|1|6|1|1|0|0|||3002274[LF]<br />
28 lorem10|5|1|1|1|1|0|||MED0015[LF]<br />
*29 lorem20|13|1|1|0|0|0||Lorem ipsum dolor sit amet, consectetur adipiscing elit[LF]<br />
*30 quis nostrud exercitation ullamco[LF]<br />
*31 laboris nisi ut aliquip ex ea commodo consequat.[LF]<br />
*32 consectetur adipiscing elit|[LF]<br />
33 lorem20|3|1|1|2|0|0|||3002407[LF]<br />
34 lorem16|11|0|1|0|0|0|||[LF]</p>
<p dir="auto">So, according to the steps, I should first replace pipe nand line feed |[LF] with [CR] (Find what: \n and Replace with: \r)<br />
I did that and lines 6, 13, 21, 32 and 34 now end with [CR]. Right away, I see this won’t work, as we’re effectively removing the last column from those lines. Remember, the rows should be 10 columns, with 9 pipes separating the columns.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46868</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46868</guid><dc:creator><![CDATA[Mark Yorkovich]]></dc:creator><pubDate>Fri, 06 Sep 2019 18:15:52 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 18:15:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-yorkovich" aria-label="Profile: Mark-Yorkovich">@<bdi>Mark-Yorkovich</bdi></a></p>
<p dir="auto">I still think the best approach is to temporarily change the [LF] you want to keep into something else, then go back and change any [LF] remaining (the bogus ones) into what you want them to be.  And finally revert the substituted line-ends back into real line-ends.</p>
<p dir="auto">Note that I don’t think there is a good way to detect a bogus [LF] if it occurs in the final field (after the 9th pipe), so I hope that doesn’t occur for you.</p>
<p dir="auto">This is rather a tough problem because the pattern can get destroyed quickly.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46867</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46867</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 06 Sep 2019 18:15:37 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 17:54:41 GMT]]></title><description><![CDATA[<p dir="auto">Okay - I’ll pull a bunch of lines out of the file into a test file and give it a whirl.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46866</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46866</guid><dc:creator><![CDATA[Mark Yorkovich]]></dc:creator><pubDate>Fri, 06 Sep 2019 17:54:41 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 17:53:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-yorkovich" aria-label="Profile: Mark-Yorkovich">@<bdi>Mark-Yorkovich</bdi></a></p>
<blockquote>
<p dir="auto">A “multistep approach” isn’t ideal in this situation</p>
</blockquote>
<p dir="auto">It seems like my 3 steps could all be of the <em>Replace All</em> variety, thus making it only 3 actions for a file of arbitrary length.  Not 3 steps you would have to repeat <em><strong>n</strong></em> times.</p>
<blockquote>
<p dir="auto">there can be characters in the last column - after the last pipe and before the LF. I failed to mention that in my post.</p>
</blockquote>
<p dir="auto">Actually, I think you did mention it, indirectly, by showing these lines, which have that attribute:</p>
<blockquote>
<p dir="auto">lorem|1|2|1|1|1|0|||9887544[LF]<br />
dolor|6|6|1|1|0|0|||123456[LF]</p>
</blockquote>
]]></description><link>https://community.notepad-plus-plus.org/post/46865</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46865</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 06 Sep 2019 17:53:41 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 15:55:39 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the reply, Alan. A “multistep approach” isn’t ideal in this situation. The file is over 100k lines - something like 70k records and I’d like to have a one-step process where I enter the regex in the Find What box, set my replacement string and click Replace All. I’ve been manually going through the file, fixing the offending records, but that way will take an incredible amount of time.</p>
<p dir="auto">I see what you’re intending to do, which made me realize that there can be characters in the last column - after the last pipe and before the LF. I failed to mention that in my post.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46861</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46861</guid><dc:creator><![CDATA[Mark Yorkovich]]></dc:creator><pubDate>Fri, 06 Sep 2019 15:55:39 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 15:05:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-yorkovich" aria-label="Profile: Mark-Yorkovich">@<bdi>Mark-Yorkovich</bdi></a> said:</p>
<blockquote>
<p dir="auto">I need to replace the “interior” line feeds with a dummy/replacement string (#$%*).</p>
</blockquote>
<p dir="auto">I missed that part upon first read.  Seems easy enough to extrapolate my solution to that, though. ;)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46859</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46859</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 06 Sep 2019 15:05:15 GMT</pubDate></item><item><title><![CDATA[Reply to Reg Ex to find lines with linefeeds in csv on Fri, 06 Sep 2019 14:42:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-yorkovich" aria-label="Profile: Mark-Yorkovich">@<bdi>Mark-Yorkovich</bdi></a></p>
<p dir="auto">I might be tempted to take a multistep approach on this one.</p>
<p dir="auto">Replace <code>|[LF]</code> with a <code>[CR]</code> -----&gt; actual FInd: <code>\|\n</code>, Replace: <code>\r</code></p>
<p dir="auto">Replace <code>[LF]</code> with a space (maybe, not sure what you want here) -----&gt; actual Find: <code>\n</code>, Replace: <code>\x20</code></p>
<p dir="auto">Replace <code>[CR]</code> with <code>|[LF]</code> -----&gt;  actual Find: <code>\r</code>, Replace: <code>|\n</code></p>
<p dir="auto">Note that the <code>[CR]</code> is just used as a temporary real-end-of-line placeholder.</p>
<p dir="auto">I’m sure other solutions are quite possible.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/46858</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/46858</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 06 Sep 2019 14:42:46 GMT</pubDate></item></channel></rss>