<?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[Help with semi-complicated regex &#x2F; Notepad++ regex issue]]></title><description><![CDATA[<p dir="auto">Hi, I need help with a regex<br />
I have a text file that contains a folder tree structure<br />
The problem is that the first file of each folder is listed on the same line as the folder<br />
Sample text: (Note, that before each “FileA” is a tab character</p>
<pre><code>Folder1
|--Folder1A	FileA
|	|--FileB
|	|--FileC
|	|--FileD
|--Folder1B	FileA
|	|--FileB
|	|--FileC
|	|--Folder1B1	FileA
|	|	|--FileB
|	|	|--FileC
|	|	|--FileD
|	|--Folder1B2	FileA
|	|	|--FileB
</code></pre>
<p dir="auto">What I though to do was as follows:</p>
<ol>
<li>find a tab character that is not preceeded by a pipe (|) --&gt; put that into group 1</li>
<li>put the remaining text on that line --&gt; group 2</li>
<li>the folder level of the next line --&gt; group 3</li>
</ol>
<p dir="auto">I was able to search that with the following:</p>
<pre><code>(?&lt;=[^\|])(\t)(.+$\r\n)([\|\t\-]+)
</code></pre>
<p dir="auto">Then, I wanted to replace that with:</p>
<pre><code>\r\n$3$2
</code></pre>
<p dir="auto">Although I though and still think this should work, notepad++ did not replace anything! It finds the text that I want, but when I press replace, it doesn’t do anything!<br />
I don’t know if this is a problem with the regex or n++, but it seems weird. and just to mention, this is not the first time I had this issue that n++ wouldn’t replace anything.</p>
<p dir="auto">Windows 10 64bit<br />
Notepad++ 6.9.1</p>
<p dir="auto">Any help will be appreciated!<br />
Thanks,<br />
David</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/11827/help-with-semi-complicated-regex-notepad-regex-issue</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Mar 2026 23:31:20 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/11827.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 19 May 2016 19:10:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Help with semi-complicated regex &#x2F; Notepad++ regex issue on Mon, 23 May 2016 18:15:17 GMT]]></title><description><![CDATA[<p dir="auto">Hi <strong>DaveyD</strong> and <strong>All</strong>,</p>
<p dir="auto">Ah, Yes ! I can apply the <strong><strong>Dail</strong>’s <code>\K</code></strong> syntax to my <strong>previous</strong> regex. So, finally, here are my <strong>two</strong> solutions :</p>
<p dir="auto">Find what : <strong><code>(?&lt;!\|)\t(.+)(\R[|\t-]+)</code></strong> which works with, either, the <strong>Replace All</strong> or the <strong>Replace</strong> button</p>
<p dir="auto">OR</p>
<p dir="auto">Find what : <strong><code>[^|]\t\K(.+)(\R[|\t-]+)</code></strong>, which <strong>ONLY</strong> works with the <strong>Replace All</strong> button</p>
<p dir="auto">For these <strong>two</strong> search regexes, the <strong>replacement</strong> regex is :</p>
<p dir="auto">Replace with : <strong><code>$2$1$2</code></strong></p>
<p dir="auto">I don’t think  that we can <strong>shorten</strong> them, anymore !</p>
<p dir="auto">Notes :</p>
<ul>
<li>
<p dir="auto">When your <strong>search</strong> regex contains a <strong><code>\K</code></strong> form, the <strong>step by step</strong> replacement <strong>never</strong> works !! That’s the <strong>normal</strong> behaviour !</p>
</li>
<li>
<p dir="auto">There are <strong>two</strong> cases, where the <strong><code>\K</code></strong> feature is <strong>mandatory</strong> and can <strong>NOT</strong> be replaced with <strong>lookbehinds</strong> :</p>
<ul>
<li>
<p dir="auto">When the regex, <strong>inside</strong> the <strong>lookbehind</strong>, could match <strong>non-fixed length</strong> strings, as, for instance, the regex <strong><code>(?&lt;=\d+)abc</code></strong></p>
</li>
<li>
<p dir="auto">When the regex, <strong>inside</strong> the <strong>lookbehind</strong> contains <strong>alternatives</strong>, of <strong>different</strong> length, as, for instance, the regex  <strong><code>(?&lt;=(12|345|6789))abc</code></strong></p>
</li>
</ul>
</li>
<li>
<p dir="auto">So, in order to get <strong>valid</strong> regular expressions, you must <strong>change</strong> them, respectively, into the <strong>two</strong>, below, which <strong>include</strong>, both, the <strong><code>\K</code></strong> syntax :</p>
<ul>
<li>
<p dir="auto"><strong><code>\d+\Kabc</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(12|345|6789)\Kabc</code></strong></p>
</li>
</ul>
</li>
<li>
<p dir="auto">On the contrary, for instance, the <strong>two</strong> regexes <strong><code>(?&lt;=\d{3})abc</code></strong> and (<strong><code>(?&lt;=(00|99))abc</code></strong> are quite <strong>valid</strong> ones. Indeed, inside the lookbehind, the <strong>former</strong> refers to a <strong>three-digits</strong> number, only and, in the <strong>later</strong>, each <strong>alternative</strong> refers to a same <strong>two-digits</strong> number :-)</p>
</li>
</ul>
<p dir="auto">You may test these <strong>4</strong> regexes against this <strong>short</strong> example text, below :</p>
<pre><code>00abc
12abc
345abc
6789abc
99abc
</code></pre>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16076</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16076</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Mon, 23 May 2016 18:15:17 GMT</pubDate></item><item><title><![CDATA[Reply to Help with semi-complicated regex &#x2F; Notepad++ regex issue on Mon, 23 May 2016 01:20:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/34">@dail</a> thanks for reminding me about the \K - I’ve used it in the past - it comes in handy when needing to use +*{} operators on lookbehinds.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/195">@guy038</a> - as always, thanks for the super-duper clarification! I’ve tried your expression as well and it works great!<br />
It would be nice if we can get all the working regex pieces together… :)</p>
<p dir="auto">Thanks to all!<br />
David</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16060</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16060</guid><dc:creator><![CDATA[DaveyD]]></dc:creator><pubDate>Mon, 23 May 2016 01:20:57 GMT</pubDate></item><item><title><![CDATA[Reply to Help with semi-complicated regex &#x2F; Notepad++ regex issue on Sun, 22 May 2016 01:27:39 GMT]]></title><description><![CDATA[<p dir="auto">Hello <strong>DaveyD</strong>, <strong>Dail</strong>, <strong>AdrianHHH</strong>, <strong>gerdb42</strong> and <strong>All</strong>,</p>
<p dir="auto"><strong>DaveyD</strong>, if your just click on the <strong>Replace All</strong> button ( instead of <strong>several</strong> hits on the <strong>Replace</strong> button ), your regex does the job <strong>correctly</strong> !</p>
<p dir="auto">We, also, get the <strong>same</strong> behaviour with the <strong>final</strong> search regex of <strong>Dail</strong>, built with the <strong><code>\K</code></strong> syntax</p>
<p dir="auto">So, to sum up : With the given <strong>example</strong> text, below, without any <strong>space</strong> inside :</p>
<pre><code>Folder1
|--Folder1A	FileA
|	|--FileB
|	|--FileC
|	|--FileD
|--Folder1B	FileA
|	|--FileB
|	|--FileC
|	|--Folder1B1	FileA
|	|	|--FileB
|	|	|--FileC
|	|	|--FileD
|	|--Folder1B2	FileA
|	|	|--FileB
</code></pre>
<p dir="auto">And the <strong>common</strong> replacement regex <strong><code>\r\n$3$2$3</code></strong> or <strong><code>\r\n\3\2\3</code></strong> :</p>
<ul>
<li>
<p dir="auto">The <strong>DaveyD</strong> search regex <strong><code>(?&lt;=[^\|])(\t)(.+$\r\n)([\|\t\-]+)</code></strong> works, with the <strong>Replace All</strong> button, ONLY</p>
</li>
<li>
<p dir="auto">The <strong>Dail</strong> search regex <strong><code>(?&lt;!\|)(\t)(.+$\r\n)([|\t-]+)</code></strong> works with, either, the <strong>Replace All</strong> or the <strong>Replace</strong> button</p>
</li>
<li>
<p dir="auto">The <strong>Gerdb42</strong> search regex <strong><code>(?&lt;![|])(\t)(.+$\r\n)([\|\t\-]+)</code></strong> works with, either, the <strong>Replace All</strong> or the <strong>Replace</strong> button</p>
</li>
<li>
<p dir="auto">The <strong>Dail</strong> search regex <strong><code>[^\|]\K(\t)(.+$\r\n)([\|\t\-]+)</code></strong> works with the <strong>Replace All</strong> button, ONLY</p>
</li>
</ul>
<hr />
<p dir="auto">Now, allow me to give you my own solution :</p>
<p dir="auto">Find what : <strong><code>(?&lt;!\|)\t(.+)(\R[|\t-]+)</code></strong></p>
<p dir="auto">Replace with : <strong><code>$2$1$2</code></strong></p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">As we don’t need the <strong>tabulation</strong> character, before <strong>FileA</strong>, we do <strong>not</strong> have to surround it with <strong>round</strong> brackets</p>
</li>
<li>
<p dir="auto">We move the <strong>End of line</strong> characters, after <strong>FileA</strong>, into the <strong>final</strong> group <strong>2</strong>. So, we do <strong>not</strong> need the part <strong><code>\r\n</code></strong>, at the beginning of the <strong>replacement</strong> regex</p>
</li>
<li>
<p dir="auto">Inside the <strong>class</strong> range <strong><code>[|\t-]</code></strong>, the <strong>escape</strong> character, before the <strong>pipe</strong> character,  is <strong>useless</strong></p>
</li>
<li>
<p dir="auto">Inside the <strong>class</strong> range <strong><code>[|\t-]</code></strong>, the <strong>escape</strong> character, before the <strong>minus</strong> character isn’t <strong>mandatory</strong>, too, if this <strong>minus</strong> sign <strong>begins</strong> or <strong>ends</strong> the <strong>class</strong> range !</p>
</li>
</ul>
<hr />
<p dir="auto"><strong>Remark</strong> :</p>
<p dir="auto">With the <strong>improved</strong> regex engine, build by <strong>François-R Boyer</strong>, in <strong>June 2013</strong> ( <strong>link</strong> below ) , as the search is done with true <strong>32 bits</strong> codepoints, instead of <strong>16 bits ones</strong>, the <strong>DaveyD</strong>’s regex does work with the <strong>Replace</strong> button , too !</p>
<p dir="auto"><a href="https://sourceforge.net/projects/npppythonplugsq/files/Beta%20N%2B%2B%20regex%20code/" rel="nofollow ugc">https://sourceforge.net/projects/npppythonplugsq/files/Beta N%2B%2B regex code/</a></p>
<p dir="auto">Unfortunately, this improved regex engine, does <strong>not</strong> work anymore, since the <strong>6.9.1</strong> version of N++ :-((( Too sad !</p>
<p dir="auto">So, to use it, just replace the current <strong>SciLexer.dll</strong> by the version of <strong>François-R Boyer</strong>, based on Scintilla <strong>2.2.7.0</strong>, in a N++ version, <strong>prior</strong> to the <strong>6.9.1</strong> one !</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S</strong> :</p>
<p dir="auto">If you <strong>copy/paste</strong> the <strong>folder tree</strong> structure, above, to do some tests, you must perform the following S/R, <strong>first</strong> :</p>
<p dir="auto">Find what : <strong><code>\x20{1,4}</code></strong></p>
<p dir="auto">Replace with : <strong><code>\t</code></strong></p>
<p dir="auto">in order to change all the <strong>space</strong> characters into <strong>tabulation</strong> characters !</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16043</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16043</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 22 May 2016 01:27:39 GMT</pubDate></item><item><title><![CDATA[Reply to Help with semi-complicated regex &#x2F; Notepad++ regex issue on Fri, 20 May 2016 13:34:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/2829">@AdrianHHH</a> <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/146">@DaveyD</a></p>
<p dir="auto">I’ve also had luck using <code>\K</code> instead of look behinds. It sets the cursor at that position. For example the original RE posted (obviously it still needed work at that point):</p>
<pre><code>(?&lt;=[^\|])(\t)(.+$\r\n)([\|\t\-]+)
</code></pre>
<p dir="auto">Would become:</p>
<pre><code>[^\|]\K(\t)(.+$\r\n)([\|\t\-]+)
</code></pre>
<p dir="auto">That way whatever <code>[^\|]</code> matches isn’t actually selected for replacement. To quote the boost documentation about <code>\K</code></p>
<blockquote>
<p dir="auto"><code>\K</code> Resets the start location of $0 to the current text position: in other words everything to the left of <code>\K</code> is “kept back” and does not form part of the regular expression match.</p>
</blockquote>
]]></description><link>https://community.notepad-plus-plus.org/post/16031</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16031</guid><dc:creator><![CDATA[dail]]></dc:creator><pubDate>Fri, 20 May 2016 13:34:45 GMT</pubDate></item><item><title><![CDATA[Reply to Help with semi-complicated regex &#x2F; Notepad++ regex issue on Fri, 20 May 2016 13:20:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/34">@dail</a> - thanks :) . That is very interesting. seems like the bug is only in positive look behind.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/2829">@AdrianHHH</a>, you’re search needed some tweaking in the last part because the pipe and the dash needed to be escaped. However, even after that it didn’t work as expected because it didn’t only find the lines with a tab in the middle. I.e., it found every line that started with a pipe and a tab.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/154">@gerdb42</a>, this works! Basically, you put dail’s search tweak, together with the last $3 that I was missing in the replacement (which I hadn’t had a chance to test since the replace wasn’t working… :) )</p>
<p dir="auto">Thanks guys<br />
David</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16030</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16030</guid><dc:creator><![CDATA[DaveyD]]></dc:creator><pubDate>Fri, 20 May 2016 13:20:37 GMT</pubDate></item><item><title><![CDATA[Reply to Help with semi-complicated regex &#x2F; Notepad++ regex issue on Fri, 20 May 2016 08:26:23 GMT]]></title><description><![CDATA[<p dir="auto">So by putting all answers together we’ll get <code>(?&lt;![|])(\t)(.+$\r\n)([\|\t\-]+)</code> for searching and <code>\r\n$3$2$3</code> for replacement.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16022</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16022</guid><dc:creator><![CDATA[gerdb42]]></dc:creator><pubDate>Fri, 20 May 2016 08:26:23 GMT</pubDate></item><item><title><![CDATA[Reply to Help with semi-complicated regex &#x2F; Notepad++ regex issue on Fri, 20 May 2016 07:55:02 GMT]]></title><description><![CDATA[<p dir="auto">I find the look behinds and look in fronts confusing and almost never use them. For this problem a simple search and replace works.</p>
<p dir="auto">Search for: ^([^\t\r\n]+)\t(.+)\r\n([| -]+)<br />
Replace with: \1\r\n\3\2\r\n\3</p>
<p dir="auto">Where:<br />
\1 contains the folder name with its preceding “^[| -]+” characters.<br />
\2 contains the  “FileA” part<br />
\3 contains the “^[| -]+” characters preceding the “FileB” part.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16020</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16020</guid><dc:creator><![CDATA[AdrianHHH]]></dc:creator><pubDate>Fri, 20 May 2016 07:55:02 GMT</pubDate></item><item><title><![CDATA[Reply to Help with semi-complicated regex &#x2F; Notepad++ regex issue on Thu, 19 May 2016 19:27:07 GMT]]></title><description><![CDATA[<p dir="auto">Definitely seems like a bug using the positive look behind. Doesn’t allow replacing the match at all.</p>
<p dir="auto">I managed to change <code>(?&lt;=[^\|])</code> into <code>(?&lt;!\|)</code> and it seemed to actually allow replacing the match. I think the regex will need tweaked some more but you seem to know what you are doing. :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16014</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16014</guid><dc:creator><![CDATA[dail]]></dc:creator><pubDate>Thu, 19 May 2016 19:27:07 GMT</pubDate></item></channel></rss>