<?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[Search and replace using named capturing group in regular expression]]></title><description><![CDATA[<p dir="auto">I want to search and replace text in a file using the named capturing group functionality of regular expressions. As an example, in the string “this is a test”, the search string “(this is)(?&lt;name1&gt; a )” matches the "this is a " successfully. But I am not sure how do I refer to this named capturing group “name1” in the replace text box. I have tried “\k&lt;name1&gt;”, “${name1}”, “${name1}” and multiple other combinations, but all have failed.</p>
<p dir="auto">Can someone please help me in identifying the correct syntax for giving the named capturing group in the replace text box.</p>
<p dir="auto">Thanks,<br />
Akbar.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/11790/search-and-replace-using-named-capturing-group-in-regular-expression</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 18:28:30 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/11790.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 May 2016 14:33:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Search and replace using named capturing group in regular expression on Fri, 10 Jun 2016 07:27:05 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">“Search / Replaces in files”-function allows only 1 line.</p>
</blockquote>
<p dir="auto">Who said so? If you know where line breaks will occur, try <code>\R</code>-Pattern as Placeholder. Or check option <code>. finds \r and \n</code>.</p>
<p dir="auto">In replacement, insert <code>\r\n</code> at places where you want line breaks.</p>
<p dir="auto">When using <code>. finds \r and \n</code> pay special attention to greedy/non greedy repeats.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16320</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16320</guid><dc:creator><![CDATA[gerdb42]]></dc:creator><pubDate>Fri, 10 Jun 2016 07:27:05 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace using named capturing group in regular expression on Thu, 09 Jun 2016 03:02:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gerdb42" aria-label="Profile: gerdb42">@<bdi>gerdb42</bdi></a> said:</p>
<blockquote>
<p dir="auto"><a href="http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html" rel="nofollow ugc">http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html</a></p>
</blockquote>
<p dir="auto">Hello<br />
How can I change many lines in one time — BUT in many files.<br />
For example 10000 files in a folder.<br />
For example I search 3 lines and instead of this lines I need to put in 10 different lines.<br />
In former times this was possible with the program Homesite (include regex / wildcard and so on), but they stopped and destroy UTF-8 documents.</p>
<p dir="auto">Can I find MANY lines with REGEX like above ???<br />
The greater problem seemed to be the inclusion of many lines, because the “Search / Replaces in files”-function allows only 1 line.</p>
<p dir="auto">Please help<br />
Mayer</p>
]]></description><link>https://community.notepad-plus-plus.org/post/16298</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/16298</guid><dc:creator><![CDATA[Gunar Mayer]]></dc:creator><pubDate>Thu, 09 Jun 2016 03:02:11 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace using named capturing group in regular expression on Sun, 17 Jul 2022 13:42:59 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/akbarmunir" aria-label="Profile: akbarmunir">@<bdi>akbarmunir</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/%D0%B2%D0%BB%D0%B0%D0%B4%D0%B8%D1%81%D0%BB%D0%B0%D0%B2-%D0%BB%D0%B0%D1%81%D1%81%D0%BA%D0%B8%D0%B9" aria-label="Profile: Владислав-Ласский">@<bdi>Владислав-Ласский</bdi></a>, and <strong>All</strong>,</p>
<p dir="auto">I’ll <strong>ONLY</strong> refer to the syntaxes, relative to <strong><code>named capturing</code></strong> groups, found in <strong>search</strong> and <strong>replacement</strong>, used by the <strong>Boost regex</strong> engine of <strong>N++</strong> !</p>
<hr />
<p dir="auto"><em>A)</em> <strong>Named capturing</strong> groups :</p>
<ul>
<li>
<p dir="auto">Each, of the <strong>two</strong> syntaxes <strong><code>(?&lt;Name&gt;.....)</code></strong>  or  <strong><code>(?'Name'.....)</code></strong>, represents a <strong>named capturing</strong> group</p>
</li>
<li>
<p dir="auto">The <strong>name</strong> must be made up of <strong>words</strong> characters only ( <strong><code>\w</code></strong> ) and must not exceed <strong>32</strong> characters</p>
</li>
<li>
<p dir="auto">The <strong>name</strong>, of a <strong>capturing</strong> group, is sensible to <strong>case</strong> ! For instance, the capturing groups <strong><code>(?&lt;Digits&gt;\d\d)</code></strong> and <strong><code>(?&lt;digitS&gt;\d\d\d)</code></strong> represent two <strong>different</strong> groups</p>
</li>
<li>
<p dir="auto">If a regex contains <strong>two or more</strong> named capturing groups with a <strong>same</strong> name, only the <strong>first</strong> one is taken in account, and <strong>all</strong> the <strong>subsequent</strong> groups are <strong>ignored</strong></p>
</li>
</ul>
<hr />
<p dir="auto"><em>B)</em> <strong>Back-references</strong> to previous <strong>named capturing</strong> groups :</p>
<ul>
<li>Each, of the <strong>six</strong> syntaxes <strong><code>\g{Name}</code></strong>, <strong><code>\g&lt;Name&gt;</code></strong>, <strong><code>\g'Name'</code></strong>, <strong><code>\k{Name}</code></strong>, <strong><code>\k&lt;Name&gt;</code></strong>, <strong><code>\k'Name'</code></strong>, represents a <strong>back-reference</strong> to the <strong>named capturing</strong> group, of name = “<strong>Name</strong>”, which must be located <strong>BEFORE</strong>, in the regex</li>
</ul>
<p dir="auto">So, as there are <strong>two</strong> forms of <strong>named capturing</strong> groups and <strong>six</strong> forms of <strong>back-references</strong>, the <strong>12</strong> possible syntaxes, below, using the <strong>named capturing</strong> group <strong>Test</strong>, would find, for instance, the string <strong>ABC</strong>, surrounded by the <strong>SAME</strong>, <strong>non null</strong> range of <strong>digits</strong> !</p>
<p dir="auto"><strong><code>(?&lt;Test&gt;\d+)ABC\g{Test}</code></strong> , <strong><code>(?&lt;Test&gt;\d+)ABC\g&lt;Test&gt;</code></strong> , <strong><code>(?&lt;Test&gt;\d+)ABC\g'Test'</code></strong></p>
<p dir="auto"><strong><code>(?&lt;Test&gt;\d+)ABC\k{Test}</code></strong> , <strong><code>(?&lt;Test&gt;\d+)ABC\k&lt;Test&gt;</code></strong> , <strong><code>(?&lt;Test&gt;\d+)ABC\k'Test'</code></strong></p>
<p dir="auto"><strong><code>(?'Test'\d+)ABC\g{Test}</code></strong> , <strong><code>(?'Test'\d+)ABC\g&lt;Test&gt;</code></strong> , <strong><code>(?'Test'\d+)ABC\g'Test'</code></strong></p>
<p dir="auto"><strong><code>(?'Test'\d+)ABC\k{Test}</code></strong> , <strong><code>(?'Test'\d+)ABC\k&lt;Test&gt;</code></strong> , <strong><code>(?'Test'\d+)ABC\k'Test'</code></strong></p>
<p dir="auto">So, <strong>ANY</strong> of these <strong>12</strong> syntaxes, matches the <strong>four</strong> lines, below :</p>
<pre><code>1ABC1
12345ABC12345
456ABC456
789ABC789
</code></pre>
<hr />
<p dir="auto"><em>C)</em> <strong>Subroutine calls</strong> to a <strong>named capturing</strong> group :</p>
<ul>
<li>Each of the <strong>two</strong> syntaxes <strong><code>(?&amp;Name)</code></strong> or <strong><code>(?P&gt;Name)</code></strong> represents a <strong>subroutine call</strong> to the regex <strong>pattern</strong> of the <strong>named capturing</strong> group, of name = “<strong>Name</strong>”,  which may be located <strong>BEFORE</strong> or <strong>AFTER</strong>, in the regex</li>
</ul>
<p dir="auto">So, as there are <strong>two</strong> forms of <strong>named capturing</strong> groups and <strong>two</strong> forms of <strong>subroutine calls</strong>, the <strong>4</strong> possible syntaxes, below, using the <strong>named capturing</strong> group <strong>Test</strong>, would find, for instance, the string <strong>ABC</strong>, surrounded by <strong>non null</strong> ranges of <strong>digits</strong> !</p>
<p dir="auto"><strong><code>(?&lt;Test&gt;\d+)ABC(?&amp;Test)</code></strong> , <strong><code>(?&lt;Test&gt;\d+)ABC(?P&gt;Test)</code></strong><br />
<strong><code>(?'Test'\d+)ABC(?&amp;Test)</code></strong> , <strong><code>(?'Test'\d+)ABC(?P&gt;Test)</code></strong></p>
<p dir="auto">So, <strong>ANY</strong> of the <strong>4</strong> syntaxes matches the <strong>nine</strong> lines below :</p>
<pre><code>1ABC1
12345ABC12345
456ABC456
789ABC789

456ABC789
789ABC456
0ABC123456789
0123456789ABC1
111ABC999
</code></pre>
<p dir="auto">And, as the <strong>subroutine call</strong> can be located <strong>BEFORE</strong> its associated <strong>named capturing</strong> group, the <strong>4</strong> syntaxes, below, are also <strong>valid</strong> ones and would find the <strong>nine</strong> lines above, too !</p>
<p dir="auto"><strong><code>(?&amp;Test)ABC(?&lt;Test&gt;\d+)</code></strong> , <strong><code>(?P&gt;Test)ABC(?&lt;Test&gt;\d+)</code></strong><br />
<strong><code>(?&amp;Test)ABC(?'Test'\d+)</code></strong> , <strong><code>(?P&gt;Test)ABC(?'Test'\d+)</code></strong></p>
<hr />
<p dir="auto"><em>D)</em> <strong>Reference</strong> to <strong>named capturing</strong> groups, in <strong>replacement</strong> :</p>
<p dir="auto">In replacement, any <strong>named</strong> group <strong><code>(?&lt;Name&gt;.....)</code></strong>  or  <strong><code>(?'Name'.....)</code></strong>, of the search part, can be <strong>re</strong>-used with the <em>UNIQUE</em> <strong>named</strong> syntax :</p>
<p dir="auto"><strong><code>$+{Name}</code></strong></p>
<hr />
<p dir="auto">It’s important to fully understand the <strong>fundamental</strong> difference between a <strong>back-reference</strong> and a <strong>subroutine call</strong> to a group, <strong>named</strong> or <strong>not</strong> :</p>
<ul>
<li>
<p dir="auto">A <strong>back-reference</strong>, to a group, represents the <strong>present match</strong> of this group</p>
</li>
<li>
<p dir="auto">A <strong>subroutine call</strong>, to a group, represents the <strong>regex pattern</strong> of this group</p>
</li>
</ul>
<p dir="auto">For instance, the <strong><code>15</code></strong> regexes, below :</p>
<ul>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC\g{Test}</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC\g&lt;Test&gt;</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC\g'Test'</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC\k{Test}</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC\k&lt;Test&gt;</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC\k'Test'</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC\g{Test}</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC\g&lt;Test&gt;</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC\g'Test'</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC\k{Test}</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC\k&lt;Test&gt;</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC\k'Test'</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC\1</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC\1</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(\d+)ABC\1</code></strong></p>
</li>
</ul>
<p dir="auto">Would match the <strong>first fourth</strong> lines, of the <strong>above</strong> example ( In other words, the numbers, surrounding the string <strong>ABC</strong>, have to be <strong>identical</strong>. Indeed, the <strong>back-references</strong> are, simply, a <strong>reference</strong> to the present number, <strong>preceding</strong> the string <strong>ABC</strong> )</p>
<p dir="auto">Whereas the <strong><code>7</code></strong> regexes, below :</p>
<ul>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC(?&amp;Test)</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC(?&amp;Test)</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?&lt;Test&gt;\d+)ABC(?P&gt;Test)</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?-i)(?'Test'\d+)ABC(?P&gt;Test)</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?&lt;Test&gt;\d+)ABC(?1)</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(?'Test'\d+)ABC(?1)</code></strong></p>
</li>
<li>
<p dir="auto"><strong><code>(\d+)ABC(?1)</code></strong></p>
</li>
</ul>
<p dir="auto">Would match the <strong><code>9</code></strong> lines of the <strong>above</strong> example ( In other words, the numbers, surrounding the string <strong>ABC</strong>, may be <strong>different</strong>. Indeed, the <strong>subroutine calls</strong> <strong><code>(?&amp;Test)</code></strong> and <strong><code>(?P&gt;Test)</code></strong> are <strong>strictly</strong> equal to <strong><code>\d+</code></strong>, the <strong>pattern</strong> of the group <strong>Test</strong> ! )</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S.</strong> :</p>
<p dir="auto">When a <strong>subroutine call</strong> is located <strong>inside</strong> the parentheses of the <strong>group</strong> to which it refers, it operates as a <strong>recursive</strong> pattern. But this is an other story … :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/15930</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/15930</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 17 Jul 2022 13:42:59 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace using named capturing group in regular expression on Fri, 13 May 2016 07:26:35 GMT]]></title><description><![CDATA[<p dir="auto">Documentation about the RegEx engine used in NPP can be found here (the Search part):</p>
<p dir="auto"><a href="http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html" rel="nofollow ugc">http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html</a></p>
<p dir="auto">and here (the Replace part):</p>
<p dir="auto"><a href="http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html" rel="nofollow ugc">http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/15921</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/15921</guid><dc:creator><![CDATA[gerdb42]]></dc:creator><pubDate>Fri, 13 May 2016 07:26:35 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace using named capturing group in regular expression on Fri, 13 May 2016 07:14:06 GMT]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I tried your solution but … Fail :( Maybe i’m don’t unerstand your post or i use wrong syntax. Where i can read actual regular expression documentation ?<br />
Tnx.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/15920</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/15920</guid><dc:creator><![CDATA[Владислав Ласский]]></dc:creator><pubDate>Fri, 13 May 2016 07:14:06 GMT</pubDate></item><item><title><![CDATA[Reply to Search and replace using named capturing group in regular expression on Thu, 12 May 2016 16:30:14 GMT]]></title><description><![CDATA[<p dir="auto">Try using <code>$+{name1}</code>. I think that <code>\g</code> and <code>\k</code> are just used within the find field to back reference a named group.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/15908</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/15908</guid><dc:creator><![CDATA[dail]]></dc:creator><pubDate>Thu, 12 May 2016 16:30:14 GMT</pubDate></item></channel></rss>