<?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[Question about replacement]]></title><description><![CDATA[<p dir="auto">Good morning!</p>
<p dir="auto">I have a question about the find and replace feature in notepad++ .   Currently, I am using regex to find the line of code I want and then using $0 to replace it on the next new line.  Is there a way to specify what line you want the replacement on?</p>
<p dir="auto">For example, I have a line of code that goes<br />
&lt;g<br />
&lt;rect<br />
x=“.255” y=“5.2”<br />
&lt;Id = name1</p>
<p dir="auto">I can capture the id=name1 using regex, but I need that line of code to replace up where the &lt;g tag is. Is there an easy/simple way to do this without having to write a program?</p>
<p dir="auto">Thanks for the help in advance!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20885/question-about-replacement</link><generator>RSS for Node</generator><lastBuildDate>Sat, 16 May 2026 02:25:06 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20885.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Mar 2021 15:13:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Question about replacement on Tue, 16 Mar 2021 16:00:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/acme1235" aria-label="Profile: Acme1235">@<bdi>Acme1235</bdi></a> said in <a href="/post/63984">Question about replacement</a>:</p>
<blockquote>
<p dir="auto">So if I understand the code correctly, you captured the (&lt;g) and then started scrolling through characters.</p>
</blockquote>
<p dir="auto">technically, captured the <code>&lt;g</code>, and characters necessary after that to make the whole match work</p>
<blockquote>
<p dir="auto">\s denotes a new line.</p>
</blockquote>
<p dir="auto"><code>\s*</code> denotes 0 or more of any whitespace (space, tab, newline)</p>
<blockquote>
<p dir="auto">The * makes it look for the id=</p>
</blockquote>
<p dir="auto">The * was the 0-or-more quantifier for the \s</p>
<p dir="auto">the <code>id="</code> makes it look for <code>id="</code></p>
<blockquote>
<p dir="auto">And then the \d denotes a digit.</p>
</blockquote>
<p dir="auto">Yep.</p>
<blockquote>
<p dir="auto">Thanks again for the help!  You’ve been a lifesaver.</p>
</blockquote>
]]></description><link>https://community.notepad-plus-plus.org/post/63986</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/63986</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 16 Mar 2021 16:00:42 GMT</pubDate></item><item><title><![CDATA[Reply to Question about replacement on Tue, 16 Mar 2021 15:54:40 GMT]]></title><description><![CDATA[<p dir="auto">So if I understand the code correctly, you captured the (&lt;g) and then started scrolling through characters.</p>
<p dir="auto">\s denotes a new line.</p>
<p dir="auto">The * makes it look for the id=</p>
<p dir="auto">And then the \d denotes a digit.</p>
<p dir="auto">Thanks again for the help!  You’ve been a lifesaver.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/63984</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/63984</guid><dc:creator><![CDATA[Acme1235]]></dc:creator><pubDate>Tue, 16 Mar 2021 15:54:40 GMT</pubDate></item><item><title><![CDATA[Reply to Question about replacement on Tue, 16 Mar 2021 15:26:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/acme1235" aria-label="Profile: Acme1235">@<bdi>Acme1235</bdi></a> ,</p>
<blockquote>
<p dir="auto"><code>(?s)(&lt;g)(.*?id=)</code></p>
</blockquote>
<p dir="auto">This FIND expression that you showed doesn’t have a group 3:</p>
<pre><code>(?s)(&lt;g)(.*?id=)
^^^^ = not a group, this is an unnumbered option
    ^^^^ = group 1
        ^^^^^^^^ = group 2
</code></pre>
<p dir="auto">… so there’s nothing to insert for $3.</p>
<p dir="auto">In your text, <code>&lt;g</code> goes into group 1, <code>\r\nid=</code> goes into group 2, and the rest of the text isn’t part of the match.  Then in your replacement, <code>$1</code> is the <code>&lt;g</code>, $3 is the empty string, so it replaces the text <code>&lt;g\r\nid=</code> with <code>&lt;g idname= trueid=00</code>; since the <code>"1"</code> was next n the string, that’s what comes next <em>after</em> the replacement – it is <em>not</em> the value of the $3.</p>
<p dir="auto">With this modified requirement, I would change tactics: don’t include the <code>id=</code> inside any group (since you don’t want to keep that syntax), and put the second group inside the quotes, so it just grabs the single-digit number.</p>
<ul>
<li>FIND = <code>(?s)(&lt;g.*?)\s*id="(\d)"</code></li>
<li>REPLACE = <code>$1 idname="$2" trueid="00$2"</code></li>
</ul>
<p dir="auto">input =&gt;</p>
<pre><code>&lt;g
id="1"&gt;
.......
&lt;/g&gt;
</code></pre>
<p dir="auto">REPLACE ALL output =&gt;</p>
<pre><code>&lt;g idname="1" trueid="001"&gt;
.......
&lt;/g&gt;
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/63979</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/63979</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 16 Mar 2021 15:26:15 GMT</pubDate></item><item><title><![CDATA[Reply to Question about replacement on Tue, 16 Mar 2021 14:32:40 GMT]]></title><description><![CDATA[<p dir="auto">So I actually ended up coding it a little bit easier in xml so I didn’t have to search ahead for a lot of lines. This is the code I have.</p>
<pre><code>&lt;g
id="1"&gt;
.......
&lt;/g&gt;
</code></pre>
<p dir="auto">The code I want returned is as follows:</p>
<pre><code>&lt;g
idname="1" trueid="001" &gt;
.......
&lt;/g&gt;

</code></pre>
<p dir="auto">This is the regex code I have tried:<br />
Find :</p>
<p dir="auto"><code>(?s)(&lt;g)(.*?id=)</code></p>
<p dir="auto">This code matches new line, puts the &lt;g in a capture group, reads up until it reaches id= and stores the rest of the line in another capture group.<br />
Replace:</p>
<p dir="auto"><code>$1 idname=$3 trueid=00$3</code></p>
<p dir="auto">From what I understand, this creates a new line, and uses capture group 3 to fill out the spots. But it doesn’t work like that.</p>
<p dir="auto">This ends up returning:</p>
<pre><code>&lt;g idname=  trueid=00"1"
</code></pre>
<p dir="auto">The two problems I’m having now is that it’s taking the quotations with the original capture group which makes it hard for the trueid statement. Also, I’m having trouble because it only seems to want to use one $3 in the replace statement.</p>
<p dir="auto">Again thanks for all the help!  I’m trying to learn regex and hope this shows some effort.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/63978</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/63978</guid><dc:creator><![CDATA[Acme1235]]></dc:creator><pubDate>Tue, 16 Mar 2021 14:32:40 GMT</pubDate></item><item><title><![CDATA[Reply to Question about replacement on Mon, 15 Mar 2021 15:35:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/acme1235" aria-label="Profile: Acme1235">@<bdi>Acme1235</bdi></a> ,</p>
<p dir="auto">In general, yes.  Use enough regex syntax to match multiple lines, and put the name1 (and maybe other things) in capture group(s), and then do a replacement that puts the text where you want it.</p>
<p dir="auto">For the specifics, it’s hard to tell, because of the wonky data you’ve shown (I don’t know whether you just omitted much, or whether the forum corrupted your input, or whether your text really does have all those <code>&lt;</code> without any <code>&gt;</code>; see the suggestions below for asking better questions, so that we know what your data looks like)</p>
<p dir="auto">For example, if your text really does look like:</p>
<pre><code>&lt;g
&lt;rect
x=".255" y="5.2"
&lt;Id = name1


&lt;g
&lt;rect
x="127" y="314"
&lt;Id = name2
</code></pre>
<p dir="auto">I might use</p>
<ul>
<li>Find What = <code>(?s-i)(^&lt;g)(.*?&lt;Id = )(\w+)</code>
<ul>
<li>the first token says “. matches newline, match case-sensitive”</li>
<li><code>(^&lt;g)</code> says “find <code>&lt;g</code> at the beginning of the line, and store in group 1”</li>
<li><code>(.*?&lt;Id = )</code> says “find up to the first <code>&lt;Id = </code> and store in group 2”</li>
<li><code>(\w+)</code> puts the next 1 or more word characters (as many as possible) into group 3</li>
</ul>
</li>
<li>Replace With = <code>${1} name="${3}"${2}${3}</code>
<ul>
<li>group 1, followed by literal <code>name="</code>, put group 3 inside the quotes, then add on groups 2 and 3; so this effectively inserts <code>name="...group3contents..."</code> between the <code>&lt;g</code> and the rest of the match</li>
</ul>
</li>
<li>Search Mode = Regular Expression</li>
<li><strong>Find Next</strong>/<strong>Replace</strong>  or <strong>Replace All</strong>, as appropriate</li>
</ul>
<p dir="auto">to get</p>
<pre><code>&lt;g name="name1"
&lt;rect
x=".255" y="5.2"
&lt;Id = name1


&lt;g name="name2"
&lt;rect
x="127" y="314"
&lt;Id = name2
</code></pre>
<p dir="auto">Since your text probably looks different, you may have to tweak that somewhat, but the idea is there.  If you need more help, follow the suggestions below for presenting your <em>before</em> <strong>and</strong> <em>after</em> text similar to the way I did, and show what regex you tried (if it was different from mine) and what you thought each piece was doing.</p>
<p dir="auto">(With regex, there’s almost always many ways of getting the same result.  Another idea I had was to just capture the <code>&lt;g</code> line, and use a long <a href="https://npp-user-manual.org/docs/searching/#assertions" rel="nofollow ugc">positive lookahead assertion</a> to find the nearest <code>Id = name1</code> and put the <code>name1</code> in a capture group inside the lookahead.  That makes the FIND more complicated, but the REPLACE easier to read.  You (or anyone interested) could take it as a homework assignment to read the linked regex docs and see if you can find an equivalent solution to mine, but that uses a capture group inside the lookahead as I described here)</p>
<p dir="auto">-—</p>
<p dir="auto"><em>Do you want regex search/replace help?  Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you.  All example text should be marked as literal text using the <code>&lt;/&gt;</code> toolbar button or manual <a href="https://community.notepad-plus-plus.org/topic/14262/how-to-markdown-code-on-this-forum/4">Markdown syntax</a>. To make <code>regex in red</code> (and so they keep their special characters like *), use backticks, like <code>`^.*?blah.*?\z`</code>. Screenshots can be pasted from the clipboard to your post using <code>Ctrl+V</code> to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have <strong>and</strong> the text you want to get from that data; include examples of things that <strong>should match</strong> and be transformed, <strong>and</strong> things that <strong>don’t match</strong> and should be left alone; show <strong>edge cases</strong> and make sure you examples are as <strong>varied</strong> as your real data.  Show the regex you already tried, <strong>and why</strong> you thought it should work; tell us what’s wrong with what you <strong>do</strong> get. Read the official <a href="https://npp-user-manual.org/docs/searching/#regular-expressions" rel="nofollow ugc">NPP Searching / Regex docs</a> and the forum’s <a href="https://community.notepad-plus-plus.org/topic/15765/faq-desk-where-to-find-regex-documentation">Regular Expression FAQ</a>. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.</em></p>
]]></description><link>https://community.notepad-plus-plus.org/post/63939</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/63939</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 15 Mar 2021 15:35:30 GMT</pubDate></item></channel></rss>