<?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[Replace certain text in lines with each line another file.]]></title><description><![CDATA[<p dir="auto">Hellooo everyone, I’ve spent hours trying to figure this out and I’ve had nothing.<br />
My query is simple. I have a text file with text of this order;</p>
<p dir="auto">str/4<br />
&lt;&lt;/Contents(100 cups)/(Date)<br />
Colour red<br />
&lt;&lt;/Contents(080 bowls)/(Date)<br />
Status used<br />
Pack team<br />
&lt;&lt;/Contents(200 John)/(Date)<br />
School house</p>
<p dir="auto">And another text file with a list of words in the order;</p>
<p dir="auto">Tree house<br />
Colon format<br />
Same variable</p>
<p dir="auto">Now the question is, how do I search or match the text between “Contents(”  and  “)” in each line, ie. 100 cups, 080 bowls, 200 John and replacementreplace it with the text in each line of my second file? . The final result should look like;</p>
<p dir="auto">str/4<br />
&lt;&lt;/Contents(Tree house)/(Date)<br />
Colour red<br />
&lt;&lt;/Contents(Colon format)/(Date)<br />
Status used<br />
Pack team<br />
&lt;&lt;/Contents(Same variable)/(Date)<br />
School house</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/16287/replace-certain-text-in-lines-with-each-line-another-file</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 19:35:05 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/16287.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Sep 2018 18:03:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Sun, 09 Sep 2018 19:59:44 GMT]]></title><description><![CDATA[<p dir="auto">Apologies <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: scott-sumner">@<bdi>scott-sumner</bdi></a>, my post on “best” regex and “trying to outdo each other” was not meant seriously (;-D). And yes our primary goal here is to help the OP with their problem. I do still think though that we are trying to make our regex’s more efficient through this process. Does that equate to “best”, possibly in a roundabout way? And yes more efficient doesn’t necessarily mean faster, it may mean less complicated for the OP to understand and follow.</p>
<p dir="auto">And I welcome having others critique my regex, thanks <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>, your “shortened” version of my regex was welcomed. I hadn’t spent a lot of time on the regex, I was mainly concerned with looking for a “more efficient”/“less complicated” solution.</p>
<p dir="auto">Thanks<br />
Terry :-))</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34726</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34726</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 09 Sep 2018 19:59:44 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Sat, 08 Sep 2018 16:41:30 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/gideon-addai" aria-label="Profile: gideon-addai">@<bdi>gideon-addai</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: scott-sumner">@<bdi>scott-sumner</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> and <strong>All</strong>,</p>
<p dir="auto"><strong>Scott</strong>, when you said :</p>
<blockquote>
<p dir="auto">So there is little value in presenting something to a solved problem that shaves a few characters off a regex…</p>
</blockquote>
<p dir="auto">I think that it’s… just the case of my <strong>last</strong> post ;-)) Of course, I agree with you that <strong>Terry-r</strong>’s regex works <strong>nice</strong> and that my <strong>last</strong> contribution was <strong>not essential</strong> at all ! However, sometimes, I, simply, think that a <strong>shorter</strong> regex may be <strong>more easily</strong> understood, for <strong>everybody</strong> !</p>
<p dir="auto">But, eventually, you’re <strong>right</strong> : the <strong>best</strong> regex, in terms of <strong>number</strong> of matches and minimum execution <strong>speed</strong>, is <strong>not</strong> always the <strong>shortest</strong> one ! And, generally, building a good <strong>generic</strong> regex, which can suit in <strong>many</strong> texts, at the same time, is rather <strong>difficult</strong> to achieve !</p>
<p dir="auto">Finally ,instead of speaking about the concept of <strong>“best”</strong> regex, we would rather speak about the <strong>most suitable</strong> regex for <strong>each</strong> OP :-))</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34719</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34719</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 08 Sep 2018 16:41:30 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Sat, 08 Sep 2018 13:24:47 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:</p>
<blockquote>
<p dir="auto">We’re all trying to outdo each other now with the BEST regex to solve this problem</p>
</blockquote>
<p dir="auto">No…no…no…please let’s <em><strong>NOT</strong></em> do this here.  Maybe on a forum strictly dedicated to regex, but not here.</p>
<p dir="auto">For the record, I don’t post to present a “better” regex to solve a problem that has already been solved.  I might, however, post to show a new twist on something…in this case the technique to hold down a keycombo to repeatedly run a <strong>Replace All</strong>…often a very effective technique that makes writing the necessary regex faster and less complicated.  It’s not a brand-new twist (running repeated <strong>Replace All</strong>s), but it doesn’t get discussed a huge amount here.</p>
<p dir="auto">Also, in this case, I had my solution mostly composed already when <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> submitted his post first…it would have been disheartening to hit <em>Discard</em> on so much text.  :-)</p>
<p dir="auto">I don’t think there’s a lot of value in a “best” regex for typical usage by Notepad++ users.  Most simply want a solution to their problem so they can move on.  So there is little value in presenting something to a solved problem that shaves a few characters off a regex…unless there is a key point also being made (which should definitely be elaborated on with additional text!). This is not intended to ignore others who might put their regex into a production environment where it will be run all the time–in these cases regex efficiency (one version of “best”) is critical…but again that is not typically the case here.  And a final thought:  a “best” regex, in terms of said efficiency, is often NOT the shortest one.  :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34718</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34718</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Sat, 08 Sep 2018 13:24:47 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Sat, 08 Sep 2018 10:19:19 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/gideon-addai" aria-label="Profile: gideon-addai">@<bdi>gideon-addai</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: scott-sumner">@<bdi>scott-sumner</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> and <strong>All</strong>,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gideon-addai" aria-label="Profile: gideon-addai">@<bdi>gideon-addai</bdi></a>, your method, involving the <strong>TextFX</strong> plugin just needs a <strong>lot</strong> of manipulations. But if you are just <strong>used</strong> to <strong>TextFX</strong>, why not !</p>
<hr />
<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>, I think that your regex, at step <strong><code>#9</code></strong>, in your <strong>last</strong> post, could be <strong>shortened</strong> a bit, as below :</p>
<p dir="auto">SEARCH <strong><code>(?-s)\d+\h(.+?\().+?(\).+)\R\d+\h(.+)</code></strong></p>
<p dir="auto">REPLACE <strong><code>\1\3\2</code></strong></p>
<p dir="auto">So, from the text, in tab <strong><code>#3</code></strong>  :</p>
<pre><code class="language-diff">1 03 &lt;&lt;/Contents(100 cups)/(Date)
2 Tree house
3 07 &lt;&lt;/Contents(080 bowls)/(Date)
4 Colon format
5 13 &lt;&lt;/Contents(200 John)/(Date)
6 Same variable
</code></pre>
<p dir="auto">It would give :</p>
<pre><code class="language-diff">03 &lt;&lt;/Contents(Tree house)/(Date)
07 &lt;&lt;/Contents(Colon format)/(Date)
13 &lt;&lt;/Contents(Same variable)/(Date)
</code></pre>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34716</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34716</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 08 Sep 2018 10:19:19 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Sat, 08 Sep 2018 05:38:32 GMT]]></title><description><![CDATA[<p dir="auto">Another solution</p>
<ol>
<li>First tab has the original file</li>
<li>Second tab has the replacement strings, 1 per line</li>
<li>For each of the tabs (1 &amp; 2) select the left most position in line 1. Select Edit, Column editor. Select text to add and type in a space, then again select column editor and for the first tab select number using 1, increase by 2 (leading zeros ticked). For the second tab select 2, increase by 2 (leading zeros ticked). Both tabs have increasing numbers seperated by a space from the original text on each line.</li>
<li>For the first tab, Search, Mark. Tick “Bookmark line” and type in the character string that determines it is a line needing (partial) replacement.</li>
<li>Create a new tab (third tab) and cut the bookmarked lines to it, Search, Bookmark, Cut bookmarked lines. Select Tab #3 and paste.</li>
<li>Repeat step 3 on tab #3, adding first a space, then a number, again start at 1, increase by 2 (leading zeros ticked).</li>
<li>Copy the contents of tab #2 to the bottom of tab#3.</li>
<li>Edit, Line Operations, Sort the lines as integer ascending. Add a blank line at bottom.</li>
<li>It is a simple matter to merge the 2nd line of each pair into position in the first line, and removing the first number on the first line of the pair.</li>
<li>Copy the contents of tab #3 back to tab #1.</li>
<li>Edit, Line Operations, Sort the lines as integer ascending.</li>
<li>Remove the numbers and space at the start of each line.</li>
</ol>
<p dir="auto">For the example provided the regex’s are:<br />
#9 Find what: <code>\d+\h(\d+\h)(.+?Contents\().+?(\).+?\R)\d+\h(.+)\R</code><br />
Replace with: <code>\1\2\4\3</code><br />
#12 Find what: <code>\d+\h</code><br />
Replace with: <code>empty field here</code></p>
<p dir="auto">So is it any better than <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> solution? I think it is marginally. First off it does not require finding out the number (although to be fair as <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> said, just look at the number of the last line). It does look a bit less complex as no need to have the original and replacement text “linked” so number of lines between remains constant, see “You should see, in new 1 tab, the following text :” and the image.<br />
The main regex is a lot neater, less complex. The 2nd regex is very basic.<br />
It also does not require any PlugIn as per OP’s own solution using TextFX, so more portable. And the OP’s solution also had 12 steps, <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> had 11.</p>
<p dir="auto">This was not my original idea as per previous post, but I happened to think of this along the way. So I may (or NOT) yet provide another alternative.</p>
<p dir="auto">Not yet tested is how to redesign this when the original text to be replaced covers multiple lines!</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34714</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34714</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sat, 08 Sep 2018 05:38:32 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Sat, 08 Sep 2018 01:59:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gideon-addai" aria-label="Profile: Gideon-Addai">@<bdi>Gideon-Addai</bdi></a> , see what you’ve done to the team @Notepad++ community (<a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>)! Your problem, on top of the one I had previously provided a solution for has really set the team off. We’re all trying to outdo each other now with the BEST regex to solve this problem.;-D</p>
<p dir="auto">Of course as we all realize, Notepad++/regex was never designed for such a task (without plugins or lots of preperation). And whilst we can make it do it (in a round about way), in all seriousness I think a script, be it Python or something else would do the job much easier. But therein lies the rub. To create a script requires an even greater learning curve. Not many are willing to take that step, if at all they can remain within the “REGEX” world!</p>
<p dir="auto">Terry</p>
<p dir="auto">PS just wait <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: scott-sumner">@<bdi>scott-sumner</bdi></a>, I’ve got the gloves off now. An idea is percolating within the grey matter. It’s a bit far fetched but I’ll follow it as far as it will take me.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34713</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34713</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sat, 08 Sep 2018 01:59:47 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Sat, 08 Sep 2018 00:00:34 GMT]]></title><description><![CDATA[<p dir="auto">Thanks to you guys for all the helpful comments. @Terry R, the entries am changing are many, a thousand maybe. There is this other method I tried that worked just fine. Though it kinda included quiet a handful of steps.</p>
<p dir="auto">It mainly involves using the Alt+Shift selection method and TextFX plugin. The aim is to try and get all lines with "&lt;&lt;/Contents(…)/(Date) following each other, replace everything within “Contents(” and “)” with a character,  and replace that character with text from second file and sort everything in it original order.</p>
<p dir="auto">Insert the line number for each line: This will lead us back to the original order.</p>
<ol>
<li>
<p dir="auto">Select the first character in each line using Alt+Shift and arrow keys.</p>
</li>
<li>
<p dir="auto">Select TextFX&gt;&gt;TextFX Tools&gt;&gt;T:Insert line numbers. The result looked like this;</p>
<pre><code>                00000001 str/4
                00000002 &lt;&lt;/Contents(100 cups)/(Date)
                00000003 Colour red
                00000004 &lt;&lt;/Contents(080 bowls)/(Date)
                00000005 Status used
                00000006 Pack team
                00000007 &lt;&lt;/Contents(200 John)/(Date)
                00000008 School house
</code></pre>
</li>
</ol>
<p dir="auto">Sort original data in ascending order: This will get the lines &lt;&lt;/Contents(…)/(Date) following each other<br />
3. Repeat step 1 for the orginal data (<strong>not</strong> the inserted line numbers)<br />
4. Select TextFX&gt;&gt;TextFX Tools&gt;&gt;T:Sort lines case insensitive (at column). The result looked like this</p>
<pre><code>                  00000004 &lt;&lt;/Contents(080 bowls)/(Date)
                  00000002 &lt;&lt;/Contents(100 cups)/(Date)
                  00000007 &lt;&lt;/Contents(200 John)/(Date)
                  00000003 Colour red
                  00000006 Pack team
                  00000008 School house
                  00000005 Status used
                  00000001 str/4
</code></pre>
<p dir="auto">Search and Replace everything between “Contents(” and “)” with a character (0 maybe): This will help us easily replace text from the second file (ie. the content of “Contents(” and “)” don’t contain the same number of characters)<br />
5. Press Ctrl+H<br />
6. Search  (nts\(.*?\)/)} and replace with nts\(0\)/  with regular expression checked (might be a better regex to do this though). The result looked like this</p>
<pre><code>                00000004 &lt;&lt;/Contents(0)/(Date)
                00000002 &lt;&lt;/Contents(0)/(Date)
                00000007 &lt;&lt;/Contents(0)/(Date)
                00000003 Colour red
                00000006 Pack team
                00000008 School house
                00000005 Status used
                00000001 str/4
</code></pre>
<p dir="auto">Replace all 0 with text from second file<br />
7.  Use Alt+Shift+arrow keys, to select all columns in the second file (<strong>Don’t</strong> use Ctrl+a) and copy.<br />
8. Select all 0 between “Contents(” and “)” like you did in step 1 and 3<br />
9. Press Ctrl+v to paste all-column-copied text from second file. The result looked like this</p>
<pre><code>               00000004 &lt;&lt;/Contents(Tree house)/(Date)
               00000002 &lt;&lt;/Contents(Colon format)/(Date)
               00000007 &lt;&lt;/Contents(Same variable)/(Date)
               00000003 Colour red
               00000006 Pack team
               00000008 School house
               00000005 Status used
               00000001 str/4
</code></pre>
<p dir="auto">Select and sort the numbers from step 2 in ascending order: This will restore the original order<br />
10. Using the same Alt+Shift+arrow keys approach, select all the beginning numbers<br />
11. Select TextFX&gt;&gt;TextFX Tools&gt;&gt;T:Sort lines case insensitive (at column). The result looked like this;</p>
<pre><code>                 00000001 str/4
                 00000002 &lt;&lt;/Contents(Colon format)/(Date)
                 00000003 Colour red
                 00000004 &lt;&lt;/Contents(Tree house)/(Date)
                 00000005 Status used
                 00000006 Pack team
                 00000007 &lt;&lt;/Contents(Same variable)/(Date)
                 00000008 School house
</code></pre>
<p dir="auto">Finally  delete all beginning numbers and space: This will restore the orginal format<br />
12. Use the same Alt+Shift+arrow keys to select all number and space columns and delete</p>
<p dir="auto">It involves a number of steps like I said and probably might not be the best approach, but I hope the idea would help someone.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34712</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34712</guid><dc:creator><![CDATA[Gideon Addai]]></dc:creator><pubDate>Sat, 08 Sep 2018 00:00:34 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Fri, 07 Sep 2018 22:48:28 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/gideon-addai" aria-label="Profile: gideon-addai">@<bdi>gideon-addai</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: scott-sumner">@<bdi>scott-sumner</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Ah, <strong>Scott</strong>, I was about to post when I just saw your reply. Interesting use of <strong>named</strong> groups, both in <strong>search</strong> and <strong>replacement</strong> ! I agree that my regex needs more <strong>data preparation</strong> ! Regarding the <strong>second</strong> drawback, you’re teasing me aren’t you :-)) Not very difficult to get the <strong>line number</strong> of the <strong>last</strong> line of a file, in the <strong>status</strong> bar !</p>
<p dir="auto">So, here is, below, a <strong>second</strong> version of the <strong>regex</strong> S/R, of my <strong>previous</strong> post, where I, simply, change the logic of the <strong>modifiers</strong> :</p>
<p dir="auto">SEARCH <strong><code>(?s)(?&lt;=Contents\()(.+?)(?=\)/.+\1\R(?:[^\r\n]+\R){3}([^\r\n]+))|^---.+</code></strong></p>
<p dir="auto">REPLACE <strong><code>?2\2</code></strong></p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">Now, the <strong><code>(?s)</code></strong> <strong>modifier</strong> is set, by <strong>default</strong>. That is to say that the <strong>dot</strong> <strong><code>.</code></strong> can match, absolutely, <strong>any single</strong> character</p>
</li>
<li>
<p dir="auto">In that case, of course :</p>
<ul>
<li>
<p dir="auto">The regex <strong><code>(?-s).+\R</code></strong> must be changed as <strong><code>(?s)[^\r\n]+\R</code></strong></p>
</li>
<li>
<p dir="auto">The regex <strong><code>(?-s).+</code></strong> must be changed as <strong><code>(?s)[^\r\n]+</code></strong></p>
</li>
</ul>
</li>
</ul>
<hr />
<p dir="auto">BTW, I found out, in the list of <strong>regex tools</strong>, referenced on the <strong><a href="http://www.rexegg.com" rel="nofollow ugc">www.rexegg.com</a></strong> site, an <strong>amazing on-line</strong> tool, at :</p>
<p dir="auto"><a href="https://www.debuggex.com/" rel="nofollow ugc">https://www.debuggex.com/</a></p>
<ul>
<li>
<p dir="auto">Choose the <strong><code>PCRE</code></strong> flavor, instead of the default <strong>JavaScript</strong> one</p>
</li>
<li>
<p dir="auto">Then, in the <strong>Regular Expression editor</strong> area,  paste your <strong>regex</strong>, to test</p>
</li>
<li>
<p dir="auto">And, in the <strong>Text String Editor</strong> area, paste your <strong>test data</strong></p>
</li>
</ul>
<p dir="auto">For instance, see my <strong>second</strong> regex version, above, at the address, below :</p>
<p dir="auto"><a href="https://www.debuggex.com/r/LUBgLokvpxHUJnrv" rel="nofollow ugc">https://www.debuggex.com/r/LUBgLokvpxHUJnrv</a></p>
<p dir="auto"><strong>Astonishing</strong>, isn’t it ?</p>
<p dir="auto"><strong>IMPORTANT</strong> :</p>
<ul>
<li>
<p dir="auto">Before pasting your regex, in <strong><code>Debuggex</code></strong> site :</p>
</li>
<li>
<p dir="auto">Change any syntax <strong><code>\R</code></strong> into <strong><code>\n</code></strong></p>
</li>
<li>
<p dir="auto">Change any syntax <strong><code>\r</code></strong> into <strong><code>\n</code></strong></p>
</li>
<li>
<p dir="auto">Change any syntax <strong><code>\r\n</code></strong> into <strong><code>\n</code></strong></p>
</li>
</ul>
<p dir="auto">Hence, <strong>paste</strong> the regex <strong><code>(?s)(?&lt;=Contents\()(.+?)(?=\)/.+\1\n(?:[^\r\n]+\n){3}([^\r\n]+))|^---.+</code></strong></p>
<hr />
<p dir="auto">I’ll probably <strong>test</strong> some regex tools and, soon, I’ll add some <strong>links</strong> to the <strong>main</strong> tools, in the <strong>FAQ Desk</strong> post, relative to <strong>regex documentation</strong> :-))</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34711</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34711</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Fri, 07 Sep 2018 22:48:28 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Fri, 07 Sep 2018 14:11:24 GMT]]></title><description><![CDATA[<p dir="auto">So <a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>’s solution is a good one, and I like that when it is finished executing, there is no “clean-up” of extraneous data, as well as it requires only one <strong>Replace All</strong> action.  It only has 2 minor drawbacks: it requires more data preparation, and it requires a count to be embedded (reference the <code>{3}</code> part).</p>
<p dir="auto">I’ll propose the following solution (drawback: requires multiple <strong>Replace All</strong> actions); prepare data as follows, all in one file (put lines of replacement data at the top, followed by a line of 10 dashes, followed by the main file data):</p>
<pre><code class="language-z">Tree house
Colon format
Same variable
----------
str/4
&lt;&lt;/Contents(100 cups)/(Date)
Colour red
&lt;&lt;/Contents(080 bowls)/(Date)
Status used
Pack team
&lt;&lt;/Contents(200 John)/(Date)
School house
</code></pre>
<p dir="auto">Do the following:</p>
<p dir="auto">Invoke <strong>Replace</strong> dialog (default key: ctrl+h)<br />
<strong>Find what</strong> zone: <code>(?-i)(?:(?&lt;group1&gt;(?-s).+)(?&lt;group2&gt;(?s).+?-{10}.+?Contents\()\d+ \w+)|(?:\R+-{10}\R)</code><br />
<strong>Replace with</strong> zone: <code>$+{group2}$+{group1}</code><br />
<strong>Wrap around</strong> checkbox: ticked<br />
<strong>Search mode</strong> selection: <em>Regular expression</em><br />
Action: Press <strong>Replace All</strong> button repeatedly (or hold down it’s <em><strong>Alt+a</strong></em> accelerator) until you see <strong>Replace All: 0 occurrences were replaced.</strong></p>
<p dir="auto">Note: I used named groups (“group1”, “group2”) here just for an added twist on regex…I didn’t come up with great names for the groups, however!</p>
<p dir="auto">Perhaps it is interesting to actually see the steps the replacement goes through to transform the data…it’s short…so:</p>
<h4>First match (top) and post-first-match replacement (bottom):</h4>
<p dir="auto"><img src="https://i.imgur.com/QsnzV8s.png" alt="Imgur" class=" img-fluid img-markdown" /></p>
<p dir="auto">Note: “group1” is the initial yellow color in the top part, “group2” is the brown color, “group3” is the final yellow color in the top part</p>
<h4>Second match (top) and post-second-match replacement (bottom):</h4>
<p dir="auto"><img src="https://i.imgur.com/hbfltxB.png" alt="Imgur" class=" img-fluid img-markdown" /></p>
<h4>Third match (top) and post-third-match replacement (bottom):</h4>
<p dir="auto"><img src="https://i.imgur.com/swSGvDg.png" alt="Imgur" class=" img-fluid img-markdown" /></p>
<h4>Fourth match (top) and post-fourth-match replacement (bottom) – this is merely a “clean-up” step:</h4>
<p dir="auto"><img src="https://i.imgur.com/QY8PuSx.png" alt="Imgur" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/34703</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34703</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Fri, 07 Sep 2018 14:11:24 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Sat, 19 Nov 2022 20:32:17 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/gideon-addai" aria-label="Profile: gideon-addai">@<bdi>gideon-addai</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: scott-sumner">@<bdi>scott-sumner</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">I think I found out a <strong>solution</strong>, which needs <strong>ONE</strong> click, only, of the <strong><code>Replace All</code></strong> button :-)) So ,</p>
<ul>
<li>
<p dir="auto">Copy/paste your data file in N++ <strong><code>new 1</code></strong> tab</p>
</li>
<li>
<p dir="auto"><strong>Again</strong>, copy and paste your data file in <strong><code>new 2</code></strong> tab</p>
</li>
<li>
<p dir="auto">Let’s suppose we just have this <strong>part</strong> of your file, below, as <strong>sample</strong> :</p>
</li>
</ul>
<pre><code class="language-diff">str/4
&lt;&lt;/Contents(100 cups)/(Date)
Colour red
&lt;&lt;/Contents(080 bowls)/(Date)
Status used
Pack team
&lt;&lt;/Contents(200 John)/(Date)
School house
</code></pre>
<ul>
<li>
<p dir="auto">Then, in <strong><code>new 2</code></strong> tab, open the <strong>Replace</strong> dialog ( <strong><code>Ctrl + H</code></strong> )</p>
</li>
<li>
<p dir="auto">Select the <strong><code>Regular expression</code></strong> search mode</p>
</li>
<li>
<p dir="auto">Tick the <strong><code>Wrap around</code></strong> option</p>
</li>
</ul>
<p dir="auto">SEARCH <strong><code>(?-si)^&lt;&lt;/Contents\((.+)\).+|.+\R</code></strong></p>
<p dir="auto">REPLACE <strong><code>?1\1</code></strong></p>
<ul>
<li>Click on the <strong><code>Replace All</code></strong> button</li>
</ul>
<p dir="auto">You should get, in <strong><code>new 2</code></strong> tab, the list of <strong>all</strong> the strings located between the strings <strong>&lt;&lt;/Contents(</strong> and <strong>)/(Date)</strong></p>
<pre><code class="language-diff">100 cups
080 bowls
200 John
</code></pre>
<ul>
<li>
<p dir="auto">Now, in <strong><code>new 1</code></strong> tab, after a <strong>separation</strong> line ( I personally chose a line of <strong>tildes</strong> ), <strong>append</strong> all the <strong><code>new 2</code></strong> contents</p>
</li>
<li>
<p dir="auto">Then, copy/paste your list of <strong>new</strong> strings, in <strong><code>new 3</code></strong> tab</p>
</li>
<li>
<p dir="auto">And append all <strong><code>new 3</code></strong> contents at the very <strong>end</strong> of <strong><code>new 1</code></strong> tab, after, again, a <strong>separation</strong> line, with <strong>tildes</strong></p>
</li>
</ul>
<p dir="auto">You should see, in <strong><code>new 1</code></strong> tab, the <strong>following</strong> text :</p>
<pre><code class="language-diff">str/4
&lt;&lt;/Contents(100 cups)/(Date)
Colour red
&lt;&lt;/Contents(080 bowls)/(Date)
Status used
Pack team
&lt;&lt;/Contents(200 John)/(Date)
School house
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100 cups
080 bowls
200 John
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tree house
Colon format
Same variable
</code></pre>
<ul>
<li>Finally, open, again the <strong>Replace</strong> dialog and perform, in the <strong><code>new 1</code></strong> tab, the <strong>regex</strong> S/R, below :</li>
</ul>
<p dir="auto">SEARCH <strong><code>(?-s)(?&lt;=Contents\()(.+?)(?=\)/(?:(?s).+)\1\R(?:.+\R){3}(.+))|(?s)^~~~.+</code></strong></p>
<p dir="auto">REPLACE <strong><code>?2\2</code></strong></p>
<p dir="auto">After a <strong>single</strong> click, on the <strong><code>Replace All</code></strong> button ( Do <strong>not</strong> use the <strong><code>Replace</code></strong> button ! ), you should get your <strong>expected</strong> text :</p>
<pre><code class="language-diff">str/4
&lt;&lt;/Contents(Tree house)/(Date)
Colour red
&lt;&lt;/Contents(Colon format)/(Date)
Status used
Pack team
&lt;&lt;/Contents(Same variable)/(Date)
School house
</code></pre>
<p dir="auto">Voila !</p>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">First, note the <strong>parentheses</strong> symbols, <strong><code>(</code></strong> and <strong><code>)</code></strong>, must be <strong>escaped</strong> with the <strong><code>\</code></strong> symbol to be considered as <strong>literals</strong> !</p>
</li>
<li>
<p dir="auto">As usual, at beginning, the <strong><code>(?-s)</code></strong> <strong>modifier</strong> means that the <strong>dot</strong> <strong><code>.</code></strong> character will match any <strong>single standard</strong> character</p>
</li>
<li>
<p dir="auto">The <strong>main</strong> search , <strong><code>(.+?)</code></strong>, stands for the <strong>shortest non-null</strong> range of characters, stored as <strong>group <code>1</code></strong> for later use, but ONLY IF <strong>two</strong> conditions are <strong>true</strong> :</p>
<ul>
<li>
<p dir="auto">It must be <strong>preceded</strong> with the string <strong><code>Contents\(</code></strong>, due to the the <strong>look-behind</strong> <strong><code>(?&lt;=Contents\()</code></strong></p>
</li>
<li>
<p dir="auto">It must <strong>match</strong> the regex <strong><code>\)/(?:(?s).+)\1\R(?:.+\R){3}(.+)</code></strong>, due to the <strong>look-ahead</strong> <strong><code>(?=\)/(?:(?s).+)\1\R(?:.+\R){3}(.+))</code></strong></p>
<ul>
<li>
<p dir="auto">The string <strong><code>)/</code></strong>, due to the regex part <strong><code>\)/</code></strong></p>
</li>
<li>
<p dir="auto">The longest <strong>multi-lines non-null</strong> range of characters, due to the <strong>non-capturing</strong> group <strong><code>(?:(?s).+)</code></strong></p>
</li>
<li>
<p dir="auto">Till the <strong>group <code>1</code></strong> contents, ( your <strong>initial</strong> string between <strong>parentheses</strong> ), with its <strong>end of line</strong>, due to the syntax <strong><code>\1\R</code></strong></p>
</li>
<li>
<p dir="auto">Then followed with <strong><code>3</code> complete</strong> lines, with the <strong>non-capturing</strong> group <strong><code>(?:.+\R){3}</code></strong>. Of course, if your <strong>list</strong> of strings, to modify, contains, let’s say, <strong><code>25</code></strong> values, just write <strong><code>(?:.+\R){25}</code></strong>, instead !</p>
</li>
<li>
<p dir="auto">And, finally, followed with the <strong>corresponding new</strong> string, which have to be placed between <strong>parentheses</strong>, stored as <strong>group <code>2</code></strong>, due to the <strong><code>(.+)</code></strong> regex</p>
</li>
</ul>
</li>
</ul>
</li>
<li>
<p dir="auto">Now, after <strong>all</strong> the <strong>initial</strong> strings are read, the regex engine tries the <strong>second</strong> alternative of the <strong>search</strong> regex, after the <strong><code>|</code></strong>  symbol, that is to say the regex <strong><code>(?s)^~~~.+</code></strong>, which grabs the <strong>longest</strong> range of <strong>any</strong> character, from the <strong>first separation</strong> line till the <strong>very end</strong> of the file, due to the <strong><code>(?s)</code></strong> <strong>modifier</strong> which means that <strong>dot</strong> <strong><code>.</code></strong> matches <strong>any single</strong> character ( <strong>standard</strong> and <strong>EOL</strong> one )</p>
</li>
<li>
<p dir="auto">In <strong>replacement</strong> :</p>
<ul>
<li>
<p dir="auto">If the <strong>first</strong> alternative of the <strong>search</strong> regex matched, the <strong>group <code>2</code></strong> exists and the <strong>initial</strong> string is changed into the <strong>new corresponding</strong> string, due to the <strong>conditional</strong> replacement <strong><code>?2\2</code></strong></p>
</li>
<li>
<p dir="auto">If the <strong>second</strong> alternative matched, <strong>all</strong> text, beginning at the <strong>first</strong> separation line, is <strong>deleted</strong>, as <strong>group <code>2</code></strong> does <strong>not</strong> exist !</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">Again, remember that the number <strong><code>3</code></strong>, between <strong>braces</strong>, near the <strong>end</strong> of the <strong>search</strong> regex, must be changed with the <strong>exact</strong> number of <strong>“strings”</strong> to modify, in your text</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34702</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34702</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sat, 19 Nov 2022 20:32:17 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Fri, 07 Sep 2018 00:04:19 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:</p>
<blockquote>
<p dir="auto">…but would like to know first how many entries you are changing. To find this information could you do the following…and click on the “Count” button.</p>
</blockquote>
<p dir="auto">Unless I’m missing something, it seems like you could also look at the “<em>replacements</em>” file, which has one replacement per line, and simply note the number of lines in this file–by definition this would be the count of the replacements needed.  By the “<em>replacements</em>” file, I mean the one that has this list:</p>
<pre><code class="language-z">Tree house
Colon format
Same variable
...
</code></pre>
<p dir="auto">Also, there’s another technique that’s been employed for such replacements in the past, that avoids the need to know the count and also the recording of the macro:  Set up the replacement and simply hold down the accelerator keycombo for the <strong>Replace All</strong> button…it may be alt+r…; the button will repeat the replacement operation over and over again quickly, and can be released when the status bar area of the Replace window indicates no more replacements are possible.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34693</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34693</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Fri, 07 Sep 2018 00:04:19 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Thu, 06 Sep 2018 21:37:41 GMT]]></title><description><![CDATA[<p dir="auto">@Giddeon-Addai I’ve got an appt so will be offline for a couple of hours. In the meantime I’ve cooked up a regex that might work. I’ve made an assumption (from your example) that the text inside the Contents(…) is starting with a 3 digit number. I will use that to determine which is the next Contents(…) to replace. If that is not the case then we need a method of identifying the bracket contents. Alternatively we’d need to clear out all brackets first.</p>
<p dir="auto">So you will have the file containing Contents(…) open in Notepad++. create 3 lines at the top. In the third line (so directly above the str/4 as in your example) type 10 = signs.<br />
The 2nd line (so above the = signs) leave blank.<br />
In the first line copy the other file, which contains the text we will be moving into the Contents(…) area.</p>
<p dir="auto">This is the regex that will transfer the text<br />
Find what: <code>(?-s)^(.+)(\R)(?s)(.+={10}.+?/Contents\()(?=\d{3})(?:.+?(\)))</code><br />
Replace with: <code>\3\1\4</code></p>
<p dir="auto">With the Replace mode set to “regular expression” and “wrap around” ticked, you will press the “Replace All” button. This will change 1 occurance ONLY. When you click the “Replace All” button again, it will move the 2nd lot of text. And so on…</p>
<p dir="auto">Hope this helps. If my assumptions aren’t correct, or other issues arise (or even if you wish to try the macro method), please let me know.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34692</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34692</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Thu, 06 Sep 2018 21:37:41 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Thu, 06 Sep 2018 21:08:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gideon-addai" aria-label="Profile: Gideon-Addai">@<bdi>Gideon-Addai</bdi></a> , as <a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a> pointed out, your problem is VERY similar to the solution I proposed in the link above. I could provide you with a revised solution to suit your needs, but would like to know first how many entries you are changing. To find this information could you do the following “Find” on your file that contains the “/Contents” string.<br />
Find: <code>/Contents\(</code><br />
and click on the “Count” button.</p>
<p dir="auto">As I suggested in that link, I can provide as either a macro or a regex (regular expression). It does depend on how many entries, it can get a bit tedious to repeatedly hit the “Replace All” button, when running a macro “x” times is neater. Of course setting up the macro can be a bit of an exercise.</p>
<p dir="auto">Please do read through the solution in that link as I’d like to know if you feel comfortable creating a macro if I provide the actual code.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34691</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34691</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Thu, 06 Sep 2018 21:08:20 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Thu, 06 Sep 2018 20:56:37 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Scott for the quick reply. Like you are saying, I think I might need more help on that. Less technical approach of possible. Am a bit more of a beginner. Thanks in advance.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34690</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34690</guid><dc:creator><![CDATA[Gideon Addai]]></dc:creator><pubDate>Thu, 06 Sep 2018 20:56:37 GMT</pubDate></item><item><title><![CDATA[Reply to Replace certain text in lines with each line another file. on Thu, 06 Sep 2018 18:49:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gideon-addai" aria-label="Profile: Gideon-Addai">@<bdi>Gideon-Addai</bdi></a></p>
<p dir="auto">So it seems like this kind of thing keeps coming up a lot lately!  Your problem is extremely similar to <a href="https://notepad-plus-plus.org/community/topic/16246/need-help-to-replace-tags-to-one-xml-from-another-xml" rel="nofollow ugc">this one</a>…do you think you can adapt the advice in that thread to your specific problem, or do you need more help than that?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34683</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34683</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Thu, 06 Sep 2018 18:49:08 GMT</pubDate></item></channel></rss>