<?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 text with incremented counter?]]></title><description><![CDATA[<p dir="auto">Newbie here - please be gentle! :)</p>
<p dir="auto">I’m sure there must already be a way to do this, but I haven’t yet figured it out. I’m trying to find a way to replace text with an incremented counter. For example, if I have a file containing this:</p>
<p dir="auto">= = = = = = = = = =<br />
&lt;TAG&gt;9999&lt;/TAG&gt;<br />
&lt;TAGHERE&gt;<br />
&lt;OTHERTAG&gt;Lorem ipsum dolor sit amet consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate&lt;/OTHERTAG&gt;<br />
&lt;/TAGHERE&gt;<br />
&lt;TAG&gt;9999&lt;/TAG&gt;<br />
&lt;TAGHERE&gt;<br />
&lt;OTHERTAG&gt;Lorem ipsum dolor sit amet consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate&lt;/OTHERTAG&gt;<br />
&lt;/TAGHERE&gt;<br />
&lt;TAG&gt;9999&lt;/TAG&gt;<br />
= = = = = = = = = =</p>
<p dir="auto">I’d like to replace the first occurrence of “9999” with “0”, the second occurrence of “9999” with “1”, etc., resulting in:</p>
<p dir="auto">= = = = = = = = = =<br />
&lt;TAG&gt;0&lt;/TAG&gt;<br />
&lt;TAGHERE&gt;<br />
&lt;OTHERTAG&gt;Lorem ipsum dolor sit amet consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate&lt;/OTHERTAG&gt;<br />
&lt;/TAGHERE&gt;<br />
&lt;TAG&gt;1&lt;/TAG&gt;<br />
&lt;TAGHERE&gt;<br />
&lt;OTHERTAG&gt;Lorem ipsum dolor sit amet consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate&lt;/OTHERTAG&gt;<br />
&lt;/TAGHERE&gt;<br />
&lt;TAG&gt;2&lt;/TAG&gt;<br />
= = = = = = = = = =</p>
<p dir="auto">I don’t see any way to do this through regular expressions. I’m guessing it might be possible with Python Script plugin, but I’m apparently too stupid to figure out how. Is there a way to do this with Notepad++?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/15318/replace-text-with-incremented-counter</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Jul 2026 17:19:13 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/15318.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Feb 2018 14:34:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Replace text with incremented counter? on Fri, 23 Feb 2018 18:46:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a></p>
<p dir="auto">It worked perfectly!! Thank you very much!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30538</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30538</guid><dc:creator><![CDATA[Guilherme Sommer]]></dc:creator><pubDate>Fri, 23 Feb 2018 18:46:36 GMT</pubDate></item><item><title><![CDATA[Reply to Replace text with incremented counter? on Fri, 23 Feb 2018 16:20:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guilherme-sommer" aria-label="Profile: Guilherme-Sommer">@<bdi>Guilherme-Sommer</bdi></a></p>
<p dir="auto">Maybe try something more like this?:</p>
<pre><code class="language-z">count = -1

def calculate(m):
    global count
    count += 1
    return '&lt;TAG&gt;' + str(count) + '&lt;TAG&gt;'

editor.rereplace('&lt;TAG&gt;([0-9]+)&lt;TAG&gt;', calculate);
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/30532</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30532</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Fri, 23 Feb 2018 16:20:12 GMT</pubDate></item><item><title><![CDATA[Reply to Replace text with incremented counter? on Fri, 23 Feb 2018 15:11:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a></p>
<p dir="auto">I had tried a similar code already<br />
But it’s not what I want</p>
<p dir="auto">What I did:<br />
def calculate(match):<br />
return ‘&lt;TAG&gt;%s’ % (str(int(match.group(1))+1))<br />
editor.rereplace(‘&lt;TAG&gt;([0-9]+)’, calculate)</p>
<p dir="auto">But this increments the number inside &lt;TAG&gt;<br />
Meaning this<br />
&lt;TAG&gt;120&lt;TAG&gt;<br />
&lt;TAG&gt;300&lt;TAG&gt;<br />
&lt;TAG&gt;552&lt;TAG&gt;</p>
<p dir="auto">Become this<br />
&lt;TAG&gt;121&lt;TAG&gt;<br />
&lt;TAG&gt;301&lt;TAG&gt;<br />
&lt;TAG&gt;553&lt;TAG&gt;</p>
<p dir="auto">And what I want is this<br />
&lt;TAG&gt;0&lt;TAG&gt;<br />
&lt;TAG&gt;1&lt;TAG&gt;<br />
&lt;TAG&gt;2&lt;TAG&gt;</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30530</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30530</guid><dc:creator><![CDATA[Guilherme Sommer]]></dc:creator><pubDate>Fri, 23 Feb 2018 15:11:21 GMT</pubDate></item><item><title><![CDATA[Reply to Replace text with incremented counter? on Fri, 23 Feb 2018 14:40:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/guilherme-sommer" aria-label="Profile: Guilherme-Sommer">@<bdi>Guilherme-Sommer</bdi></a></p>
<p dir="auto">This cannot be done with normal regular-expression replacement in Notepad++.</p>
<p dir="auto">Scripting is the way to go.  Have a look at the <code>editor.rereplace</code> function in the Pythonscript documentation.  There is an example there that is really close to what you want to do.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/30529</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/30529</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Fri, 23 Feb 2018 14:40:36 GMT</pubDate></item></channel></rss>