<?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[Notepad++ regex to move a line with certain string after a line with another string]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I’m looking for solution with current challenge.<br />
Current XML file:</p>
<p dir="auto">&lt;something&gt;<br />
&lt;tag1&gt;a&lt;tag1&gt;<br />
&lt;tag2&gt;b&lt;tag2&gt;<br />
&lt;tag3&gt;c&lt;tag3&gt;<br />
&lt;/something&gt;</p>
<p dir="auto">I would like a regex search and replace for all opened files in notepad (Replace All in All Opened Documents button).</p>
<p dir="auto">Goal is to move line containing certain  string, say &lt;tag3&gt; a few lines up, right after the line containing string &lt;something&gt;. Note the number of tags &lt;tag1&gt;, &lt;tag2&gt; etc. varies in different files, so regex to move line containing &lt;tag3&gt; 2 lines up wouldn’t work, but would also be great to know how to achieve that.</p>
<p dir="auto">Wanted result:<br />
&lt;something&gt;<br />
&lt;tag3&gt;c&lt;tag3&gt;<br />
&lt;tag1&gt;a&lt;tag1&gt;<br />
&lt;tag2&gt;b&lt;tag2&gt;<br />
&lt;/something&gt;</p>
<p dir="auto">I’ve been using Notepad++ for all kinds of tasks, but can’t figure this one out, any help would be gratefully appreciated. Thank you</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/22718/notepad-regex-to-move-a-line-with-certain-string-after-a-line-with-another-string</link><generator>RSS for Node</generator><lastBuildDate>Mon, 11 May 2026 06:15:27 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/22718.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 14 Mar 2022 13:05:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Notepad++ regex to move a line with certain string after a line with another string on Wed, 16 Mar 2022 11:54:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/anonymous-guy" aria-label="Profile: anonymous-guy">@<bdi>anonymous-guy</bdi></a> said in <a href="/post/75190">Notepad++ regex to move a line with certain string after a line with another string</a>:</p>
<blockquote>
<p dir="auto">I’m really grateful and if anyone has a buy me coffee page or any other way I can at least symbolically show my gratitude let me know.</p>
</blockquote>
<p dir="auto">I can take care of that as well:</p>
<p dir="auto"><img src="/assets/uploads/files/1647431600240-d9f10465-fc9c-4403-a4d5-e1b1f7ae76b9-image.png" alt="d9f10465-fc9c-4403-a4d5-e1b1f7ae76b9-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/75191</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/75191</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 16 Mar 2022 11:54:19 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ regex to move a line with certain string after a line with another string on Wed, 16 Mar 2022 11:48:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a> I tried applying your regex but it somehow didn’t work, probably it was something I did wrong so I used Alans regex for the original task.</p>
<p dir="auto">Next day I also needed exactly the regex you shared and it worked perfectly without breaking any code indents, just awesome! I’ll surely use it again in near future it would be really time consuming to try to change line order manually.</p>
<p dir="auto">Thank you so so much for taking the time and effort to share your solution and making it so clear to understand I really appreciate it.</p>
<p dir="auto"><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/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a></p>
<p dir="auto">Thank you both for your time and solutions I’m really grateful and if anyone has a buy me coffee page or any other way I can at least symbolically show my gratitude let me know.</p>
<p dir="auto">Have a great day ( :</p>
]]></description><link>https://community.notepad-plus-plus.org/post/75190</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/75190</guid><dc:creator><![CDATA[Anonymous Guy]]></dc:creator><pubDate>Wed, 16 Mar 2022 11:48:27 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ regex to move a line with certain string after a line with another string on Mon, 14 Mar 2022 16:59:37 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/anonymous-guy" aria-label="Profile: anonymous-guy">@<bdi>anonymous-guy</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">Let’s try a <strong>general</strong> method regarding the move of a <strong>first</strong> <strong><code>&lt;tag&gt;</code></strong> line <strong>before</strong> or <strong>after</strong> a <strong>second</strong> <strong><code>&lt;tag&gt;</code></strong> line, <strong>both</strong> located in a <strong>same</strong> <strong><code>&lt;tag&gt;...........&lt;/tag&gt;</code></strong> section</p>
<p dir="auto">To <strong>simplify</strong> the problem, I assume that any <strong><code>&lt;tag&gt;..........&lt;/tag&gt;</code></strong> range, between the <strong>first</strong> and <strong>second</strong> tag included, is located in a <strong>single</strong> line ( not <strong>splitted</strong> over <strong>several</strong> lines ! )</p>
<ul>
<li>
<p dir="auto">Let the <strong>first</strong> tag met, be called <strong><code>&lt;tag_A&gt;</code></strong></p>
</li>
<li>
<p dir="auto">Let the <strong>second</strong> tag met, be called <strong><code>&lt;tag_B&gt;</code></strong></p>
</li>
</ul>
<p dir="auto">Then, we can imagine the <strong>generic</strong> regex S/R, below :</p>
<p dir="auto">SEARCH <strong><code>(?-s)(^\h*</code>&lt;tag_A&gt;<code>.*\R)(?s)(.*)(?-s)(^\h*</code>&lt;tag_B&gt;<code>.*\R)</code></strong></p>
<p dir="auto">REPLACE <strong><code>\3\1\2</code></strong>    ( <strong><code>tag_B</code></strong> line is moved right <strong>before</strong> the <strong><code>&lt;tag_A&gt;</code></strong> line )<br />
REPLACE <strong><code>\1\3\2</code></strong>    ( <strong><code>tag_B</code></strong> line is moved right <strong>after</strong>    the <strong><code>&lt;tag_A&gt;</code></strong> line )<br />
REPLACE <strong><code>\2\1\3</code></strong>    ( <strong><code>tag_A</code></strong> line is moved right <strong>before</strong> the <strong><code>&lt;tag_B&gt;</code></strong> line )<br />
REPLACE <strong><code>\2\3\1</code></strong>    ( <strong><code>tag_A</code></strong> line is moved right <strong>after</strong>    the <strong><code>&lt;tag_B&gt;</code></strong> line )<br />
REPLACE <strong><code>\3\2\1</code></strong>    ( <strong><code>tag_A</code></strong> line and <strong><code>&lt;tag&gt;_B</code></strong> line are <strong>switched</strong> )</p>
<hr />
<p dir="auto">In your case, given your <em>INITIAL</em> text, below :</p>
<pre><code class="language-xml">&lt;blablabla&gt;
	&lt;edm:WebResource rdf:about="link.html&gt;
		&lt;dcterms:extent&gt;17976 KB&lt;/dcterms:extent&gt;
		&lt;dc:rights&gt;Use of this resource is governed by the terms and conditions of the Creative Commons CC BY License&lt;/dc:rights&gt;
		&lt;edm:rights rdf:resource="http://creativecommons.org/publicdomain/mark/1.0/"/&gt;
		&lt;dc:format&gt;PDF&lt;/dc:format&gt;
		&lt;dcterms:created&gt;30.3.2015&lt;/dcterms:created&gt;
	&lt;/edm:WebResource&gt;
</code></pre>
<p dir="auto">With the <strong>practical</strong> following regex S/R :</p>
<p dir="auto">SEARCH <strong><code>(?-s)(^\h*&lt;dc:rights&gt;.*\R)(?s)(.*)(?-s)(^\h*&lt;dcterms:created&gt;.*\R)</code></strong></p>
<p dir="auto">REPLACE <strong><code>\1\3\2</code></strong></p>
<p dir="auto">We get the <strong>expected</strong> results :</p>
<pre><code class="language-xml">&lt;blablabla&gt;
	&lt;edm:WebResource rdf:about="link.html&gt;
		&lt;dcterms:extent&gt;17976 KB&lt;/dcterms:extent&gt;
		&lt;dc:rights&gt;Use of this resource is governed by the terms and conditions of the Creative Commons CC BY License&lt;/dc:rights&gt;
		&lt;dcterms:created&gt;30.3.2015&lt;/dcterms:created&gt;
		&lt;edm:rights rdf:resource="http://creativecommons.org/publicdomain/mark/1.0/"/&gt;
		&lt;dc:format&gt;PDF&lt;/dc:format&gt;
	&lt;/edm:WebResource&gt;
</code></pre>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/75150</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/75150</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Mon, 14 Mar 2022 16:59:37 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ regex to move a line with certain string after a line with another string on Mon, 14 Mar 2022 15:18:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a><br />
I’m slowly achieving what I was looking for, hopefully tomorrow with a fresh start I can finish.</p>
<p dir="auto">Thank you for your help and pointers, was just trying to figure out how to adapt the regex so that the insides of first tag don’t have to be specified since they are not identical to every opened file.</p>
<p dir="auto">This works, just some line breaks to fix. Sorry for the confusion.</p>
<pre><code>(&lt;dc:rights&gt;.*)(?s)(.*?)(&lt;dcterms:created&gt;.*?&lt;/dcterms:created&gt;\R)
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/75149</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/75149</guid><dc:creator><![CDATA[Anonymous Guy]]></dc:creator><pubDate>Mon, 14 Mar 2022 15:18:11 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ regex to move a line with certain string after a line with another string on Mon, 14 Mar 2022 14:48:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/anonymous-guy" aria-label="Profile: anonymous-guy">@<bdi>anonymous-guy</bdi></a></p>
<p dir="auto">Looking at your expressions…they way you used <code>*</code> is "command-line"ish, not regular-expression-ish.</p>
<p dir="auto">So, <code>*</code> means “zero or more of the <code>thing</code> preceding”</p>
<p dir="auto"><code>thing</code> is often a single character or metacharacter, or it could be something in parens…</p>
<p dir="auto">Examples:</p>
<p dir="auto"><code>z*</code> : zero or more, as many as possible, of <code>z</code><br />
<code>.*</code> : zero or more, as many as possible, of “any single character”<br />
<code>(abc)*</code> : zero or more, as many as possible, of a run of <code>abc</code></p>
<p dir="auto">also note:</p>
<p dir="auto"><code>z*?</code> : zero or more, as <em>few</em> as possible, of <code>z</code><br />
<code>.*?</code> : zero or more, as <em>few</em> as possible, of “any single character”<br />
<code>(abc)*?</code> : zero or more, as <em>few</em> as possible, of a run of <code>abc</code></p>
<p dir="auto">There’s really no way to grasp this except reading the docs and experimenting…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/75148</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/75148</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 14 Mar 2022 14:48:06 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ regex to move a line with certain string after a line with another string on Mon, 14 Mar 2022 14:41:51 GMT]]></title><description><![CDATA[<pre><code>@alan-kilborn 
Replaced
(&lt;dc:rights&gt;Use of this resource is governed by the terms and conditions of the Creative Commons CC BY License&lt;/dc:rights&gt;\R)(?s)(.*?)(&lt;dcterms:created&gt;.*?&lt;/dcterms:created&gt;\R)
with
${1}${3}${2}

And it worked. Can the regex be configured so that you don't have to write the whole exact line just a part of it. My logic would be something like:
(*&lt;dc:rights&gt;*\R)(?s)(.*?)(&lt;dcterms:created&gt;.*?&lt;/dcterms:created&gt;\R)
but as expected it doesn't work that way.

(&lt;dc:rights&gt;*&lt;/dc:rights&gt;\R)(?s)(.*?)(&lt;dcterms:created&gt;.*?&lt;/dcterms:created&gt;\R)
Also doesn't work. 
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/75147</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/75147</guid><dc:creator><![CDATA[Anonymous Guy]]></dc:creator><pubDate>Mon, 14 Mar 2022 14:41:51 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ regex to move a line with certain string after a line with another string on Mon, 14 Mar 2022 14:19:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: alan-kilborn">@<bdi>alan-kilborn</bdi></a><br />
Thank you for your time and provided solution.</p>
<p dir="auto">You are right it works on provided example, but not on XML I’m trying to change.</p>
<p dir="auto">I understand the  general idea and played around with the regex, but don’t know why it doesn’t work jet. Tried to simplify it for easier understanding and so that it’s applicable to many situations.</p>
<p dir="auto">I removed some clutter at start of xml, what I’m trying to do is for example move line with tag <a rel="nofollow ugc">dcterms:created</a> after the line <a rel="nofollow ugc">dc:rights</a> among other moves.</p>
<p dir="auto">My guesstimate is that it doesn’t work because of xml structure, indents or something else.</p>
<pre><code>&lt;blablabla&gt;
	&lt;edm:WebResource rdf:about="link.html&gt;
		&lt;dcterms:extent&gt;17976 KB&lt;/dcterms:extent&gt;
		&lt;dc:rights&gt;Use of this resource is governed by the terms and conditions of the Creative Commons CC BY License&lt;/dc:rights&gt;
		&lt;edm:rights rdf:resource="http://creativecommons.org/publicdomain/mark/1.0/"/&gt;
		&lt;dc:format&gt;PDF&lt;/dc:format&gt;
		&lt;dcterms:created&gt;30.3.2015&lt;/dcterms:created&gt;
	&lt;/edm:WebResource&gt;
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/75146</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/75146</guid><dc:creator><![CDATA[Anonymous Guy]]></dc:creator><pubDate>Mon, 14 Mar 2022 14:19:27 GMT</pubDate></item><item><title><![CDATA[Reply to Notepad++ regex to move a line with certain string after a line with another string on Mon, 14 Mar 2022 13:32:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/anonymous-guy" aria-label="Profile: anonymous-guy">@<bdi>anonymous-guy</bdi></a></p>
<p dir="auto">So a potential problem with “generalizing” your problem for posting is that you make it too general and it doesn’t work for your real use case.</p>
<p dir="auto">Given that, I think this transforms your generalized example:</p>
<p dir="auto">Find: <code>(&lt;something&gt;\R)(?s)(.*?)(&lt;tag3&gt;.*?&lt;tag3&gt;\R)</code><br />
Replace: <code>${1}${3}${2}</code><br />
Search mode: regular expression</p>
]]></description><link>https://community.notepad-plus-plus.org/post/75143</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/75143</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 14 Mar 2022 13:32:52 GMT</pubDate></item></channel></rss>