<?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[Find duplicate variable declaration Regex]]></title><description><![CDATA[<p dir="auto">I’m looking to build a regex that will find duplicate string/variables. An example of the input as follows:</p>
<pre><code>     &lt;SymbolVar name="DATABASE_NAME" value="DB1"/&gt;
     &lt;SymbolVar name="DATABASE_NAME" value="DB2"/&gt;
     &lt;SymbolVar name="PORT" value="12345"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server1"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server2"/&gt;
</code></pre>
<p dir="auto">The returned find should match “DATABASE_NAME” and “SERVER_NAME” present both twice.</p>
<p dir="auto">My first attempt as follows, doesn’t quite cut it</p>
<p dir="auto">(?m)&lt;SymbolVar name="(\S+).<em>\R(?s).</em>?\K\1</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/24533/find-duplicate-variable-declaration-regex</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 17:38:48 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/24533.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Jun 2023 05:07:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Find duplicate variable declaration Regex on Wed, 07 Jun 2023 04:21:25 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26710">@Mark-Olson</a> / <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/195">@guy038</a></p>
<p dir="auto">Both solutions work a treat !</p>
<p dir="auto">Appreciate the fast turn around</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86895</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86895</guid><dc:creator><![CDATA[Stuart Dyer]]></dc:creator><pubDate>Wed, 07 Jun 2023 04:21:25 GMT</pubDate></item><item><title><![CDATA[Reply to Find duplicate variable declaration Regex on Tue, 06 Jun 2023 04:05:38 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/28507">@stuart-dyer</a>, <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26710">@mark-olson</a>, <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/23651">@lycan-thrope</a> and <strong>All</strong>,</p>
<p dir="auto">Oh… <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/28507">@stuart-dyer</a>, I think I’ve found an very <strong>easy</strong> way to <strong>visualize</strong> all the <strong>duplicated</strong> values of any <strong>attribute</strong>, of your <strong><code>HTML</code></strong> text , in <strong>one</strong> go !</p>
<hr />
<p dir="auto">So, let’s start with this <em>INPUT</em> text :</p>
<pre><code class="language-html">     &lt;SymbolVar name="DATABASE_NAME" value="DB1"/&gt;
     &lt;SymbolVar name="DATABASE_NAME" value="DB2"/&gt;
     &lt;SymbolVar name="ABCD" value="123"/&gt;
     &lt;SymbolVar name="PORT" value="34"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server1"/&gt;
     &lt;SymbolVar name="EFGH" value="123"/&gt;
     &lt;SymbolVar name="IJKL" value="456"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server2"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server3"/&gt;
     &lt;SymbolVar name="MNOP" value="456"/&gt;
     &lt;SymbolVar name="DATABASE_NAME" value="DB3"/&gt;
</code></pre>
<ul>
<li><strong>Duplicate</strong> your <strong>entire</strong> text, right <em>AFTER</em> a <strong>separation</strong> line of, at least, <strong><code>3</code></strong> <strong>sharp</strong> characters. If you text <strong>already</strong> contains some <strong><code>#</code></strong> characters , just use an <strong>other</strong> separator !</li>
</ul>
<p dir="auto">So, from our simple example, we get this text :</p>
<pre><code class="language-html">     &lt;SymbolVar name="DATABASE_NAME" value="DB1"/&gt;
     &lt;SymbolVar name="DATABASE_NAME" value="DB2"/&gt;
     &lt;SymbolVar name="ABCD" value="123"/&gt;
     &lt;SymbolVar name="PORT" value="34"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server1"/&gt;
     &lt;SymbolVar name="EFGH" value="123"/&gt;
     &lt;SymbolVar name="IJKL" value="456"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server2"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server3"/&gt;
     &lt;SymbolVar name="MNOP" value="456"/&gt;
     &lt;SymbolVar name="DATABASE_NAME" value="DB2"/&gt;
################
     &lt;SymbolVar name="DATABASE_NAME" value="DB1"/&gt;
     &lt;SymbolVar name="DATABASE_NAME" value="DB2"/&gt;
     &lt;SymbolVar name="ABCD" value="123"/&gt;
     &lt;SymbolVar name="PORT" value="34"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server1"/&gt;
     &lt;SymbolVar name="EFGH" value="123"/&gt;
     &lt;SymbolVar name="IJKL" value="456"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server2"/&gt;
     &lt;SymbolVar name="SERVER_NAME" value="Server3"/&gt;
     &lt;SymbolVar name="MNOP" value="456"/&gt;
     &lt;SymbolVar name="DATABASE_NAME" value="DB2"/&gt;
</code></pre>
<ul>
<li>
<p dir="auto">Open the <strong>Mark</strong> dialog ( <strong><code>Ctrl + M</code></strong> )</p>
</li>
<li>
<p dir="auto"><strong>Untick</strong> all <strong>box</strong> options</p>
</li>
<li>
<p dir="auto"><strong>Check</strong> the <strong><code>Purge for each search</code></strong> option</p>
</li>
<li>
<p dir="auto">Possibly, check the <strong><code>Bookmark line</code></strong> and <strong><code>Wrap around</code></strong> options</p>
</li>
<li>
<p dir="auto">Type in, in the <strong><code>Find what</code></strong> zone, this simple regex to <strong>mark</strong> all the <strong>duplicated</strong> values of any <strong><code>attribute</code></strong> :</p>
<ul>
<li>MARK <strong><code>(?s)="\K(.+?)(?=".*###)(?=".+?\1.+?\1)</code></strong></li>
</ul>
</li>
<li>
<p dir="auto">Click on  <strong><code>Mark All</code></strong> button</p>
</li>
</ul>
<p dir="auto">Et voilà !</p>
<hr />
<p dir="auto"><strong>Note</strong> : You can easily <strong>adapt</strong> this regex to visualize the <strong>duplicate</strong> values of a <strong>specific</strong> attribute ! For instance :</p>
<ul>
<li>
<p dir="auto">The regex <strong><code>(?s)name="\K(.+?)(?=".*###)(?=".+?\1.+?\1)</code></strong> would mark <strong>all</strong> the <strong>duplicate</strong> values of the <strong><code>name</code></strong> attribute, <strong>only</strong></p>
</li>
<li>
<p dir="auto">The regex <strong><code>(?s)value="\K(.+?)(?=".*###)(?=".+?\1.+?\1)</code></strong> would mark <strong>all</strong> the <strong>duplicate</strong> values of the <strong><code>value</code></strong> attribute, <strong>only</strong></p>
</li>
</ul>
<p dir="auto">When you finish working of your <strong><code>HTML</code></strong> file, simply <strong>delete</strong> the <strong>last</strong> part, with the <strong>separator</strong> line of <strong><code>#</code></strong> chars !</p>
<hr />
<p dir="auto">How this <strong>regex</strong> works ?</p>
<ul>
<li>
<p dir="auto">As our search is a <strong>multi</strong>-lignes one, we use the <strong><code>(?s)</code></strong> modifier to represents text as an <strong>unique</strong> line</p>
</li>
<li>
<p dir="auto">As we want to <strong>aim</strong> the values of the attributes, we <strong>first</strong> search for the string <strong><code>="</code></strong></p>
</li>
<li>
<p dir="auto">Then, due to the <strong><code>\K</code></strong> syntax, the current search is <strong>cancelled</strong> and the regex engine searches for <strong>any</strong> text till the <strong>nearest</strong> <strong><code>"</code></strong> character <strong>excluded</strong>, but <em>ONLY IF</em> <strong>two</strong> conditions are respected :</p>
<ul>
<li>
<p dir="auto">The line of <strong><code>#</code></strong> charactes must be <strong>always</strong> located <em>AFTER</em> the current search, due to the <strong><code>(?=".*###)</code></strong> look-head</p>
</li>
<li>
<p dir="auto">At least, <strong>two</strong> other occurrences, of the <strong>searched</strong> value <strong><code>\1</code></strong>, must be present, <em>AFTER</em> the <strong>current</strong> location, due to the <strong><code>(?=".+?\1.+?\1)</code></strong> look-ahead. Indeed, as we now <strong>duplicated</strong> our current file, all <strong>unique</strong> values of attributes, in this <strong>modified</strong> file, appear <strong>two</strong> times <em>ONLY</em> and so will <strong>not</strong> be marked !</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86861</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86861</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 06 Jun 2023 04:05:38 GMT</pubDate></item><item><title><![CDATA[Reply to Find duplicate variable declaration Regex on Mon, 05 Jun 2023 20:57:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/28507">@Stuart-Dyer</a> ,<br />
<a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26710">@Mark-Olson</a> has come with <strong>a</strong> solution, but I find your description of the issue to be vague and improperly defined, and if <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26710">@Mark-Olson</a> 's answer is not what you wanted, then I suggest you give a better description of your desired before and after results, before someone can adequately come up with an answer.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86852</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86852</guid><dc:creator><![CDATA[Lycan Thrope]]></dc:creator><pubDate>Mon, 05 Jun 2023 20:57:15 GMT</pubDate></item><item><title><![CDATA[Reply to Find duplicate variable declaration Regex on Mon, 05 Jun 2023 06:15:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/28507">@Stuart-Dyer</a><br />
<code>(?s-i)&lt;SymbolVar\s+name\s*=\s*"([^"]+)".+&lt;SymbolVar\s+name\s*=\s*\K"\1"</code> should do it.</p>
<p dir="auto">It will highlight every duplicate instance (that is, it won’t highlight the first occurrence of any name, only the first.</p>
<p dir="auto"><img src="/assets/uploads/files/1685945612633-b380be1f-3b9c-407d-8e29-e9b84d9754c7-image.png" alt="b380be1f-3b9c-407d-8e29-e9b84d9754c7-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">I should note that I use a bunch of <code>\s+</code> where you could probably just use a simple space and a bunch of <code>\s*</code> that can likely be omitted. That’s mostly just because I like to play it safe with my regexes and not assume that insignificant whitespace will always be the same.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86820</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86820</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Mon, 05 Jun 2023 06:15:22 GMT</pubDate></item></channel></rss>