<?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[best way to stop matching of escaped parentheses/brackets in regular expression.]]></title><description><![CDATA[<p dir="auto">As I’ve noted elsewhere, I really like the fact that NPP does bracket matching in strings and regexes that is separate from the bracket matching outside strings and regexes.<br />
However, I’m less happy about the fact that escaped parentheses and brackets are still matched. Obviously I recognize that this would be a rather irritating feature to implement and would presumably need to be implemented on a per-lexer basis, but does anyone have thoughts about the best way to achieve this?</p>
<p dir="auto">I will probably submit a feature request in Scintilla or Lexilla, but I was hoping some of the veterans here could give their thoughts.</p>
<p dir="auto"><img src="/assets/uploads/files/1680304788893-cb64e333-4e7a-416d-afc5-0237674a0c02-image.png" alt="cb64e333-4e7a-416d-afc5-0237674a0c02-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/topic/24321/best-way-to-stop-matching-of-escaped-parentheses-brackets-in-regular-expression</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 22:57:33 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/24321.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 31 Mar 2023 23:20:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to best way to stop matching of escaped parentheses/brackets in regular expression. on Sat, 15 Apr 2023 11:23:43 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> said in <a href="/post/85391">best way to stop matching of escaped parentheses/brackets in regular expression.</a>:</p>
<blockquote>
<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-olson" aria-label="Profile: mark-olson">@<bdi>mark-olson</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: ekopalypse">@<bdi>ekopalypse</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">There are a solution with <strong>recursive</strong> regexes ! Here are <strong><code>3</code></strong> kinds of <strong>recursive</strong> regex which do find <strong>paired</strong> groups of <strong>NON</strong>-escaped <strong>parentheses</strong> !</p>
<ul>
<li>
<p dir="auto">The regex <strong><code>A</code></strong> looks, from <strong>cursor</strong> position, for the <strong>greatest</strong> group of <strong>NON</strong>-escaped <strong>paired</strong> parentheses</p>
</li>
<li>
<p dir="auto">The regex <strong><code>B</code></strong> looks, from <strong>cursor</strong> position, for the <strong>greatest</strong> group of <strong>NON</strong>-escaped <strong>paired</strong> parentheses, <strong>surrounded</strong> by text <strong>different</strong> from <strong>NON</strong>-escaped parentheses</p>
</li>
<li>
<p dir="auto">The regex <strong><code>C</code></strong> looks, from <strong>cursor</strong> position, for the <strong>greatest</strong> range of characters, containing <strong>one</strong> or <strong>several</strong> group(s) of <strong>NON</strong>-escaped <strong>paired</strong> parentheses, each of them being <strong>surrounded</strong> by text <strong>different</strong> from <strong>NON</strong>-escaped parentheses</p>
</li>
<li>
<p dir="auto">Regex <strong><code>A</code></strong> : <strong><code>(?x) (?&lt;!\\) \( (?: (?: \\ [()] | [^()] ) | (?0) )* (?&lt;!\\) \)  # Regex A</code></strong></p>
</li>
<li>
<p dir="auto">Regex <strong><code>B</code></strong> : <strong><code>(?x) (?: \\ [()] | [^()] )* ( (?&lt;!\\) \( (?: (?: \\ [()] | [^()] ) | (?1) )* (?&lt;!\\) \) ) (?: \\ [()] | [^()] )*  # Regex B</code></strong></p>
</li>
<li>
<p dir="auto">Regex <strong><code>C</code></strong> : <strong><code>(?x) (?: (?: \\ [()] | [^()] )* ( (?&lt;!\\) \( (?: (?: \\ [()] | [^()] ) | (?1) )* (?&lt;!\\) \) ) (?: \\ [()] | [^()] )* )+  # Regex C</code></strong></p>
</li>
</ul>
<p dir="auto"><strong>Important</strong> : Sometimes the <strong>regex engine</strong> needs to go <strong>further</strong> on, in order to get a <strong>new paired</strong> group of parentheses to match !</p>
<hr />
<p dir="auto">To <strong>test</strong> these regexes,:</p>
<ul>
<li>
<p dir="auto"><strong>Paste</strong> the text below in a <strong>new</strong> tab</p>
</li>
<li>
<p dir="auto">Put the cursor , on the <strong>last</strong> line, <strong>right before</strong> the word <strong><code>This</code></strong></p>
</li>
<li>
<p dir="auto">Run, <strong>successively</strong>, the regexes <strong><code>A</code></strong>, <strong><code>B</code></strong> and <strong><code>C</code></strong></p>
</li>
</ul>
<pre><code class="language-diff">C     -------------------------------------------------------------------------- -----------------------------------------------------
B     ------------------------|------------------------------------------------- -----------------------------------------------------
A         --------------       --------------------------------------                     ---------------------------------------
     x    1 2        1 0       1            2                     1 0           x         1 2       1                           0
This ( is ( ( a very ) ) small ( test \( to ( verify \( if \) all ) ) these \)  ( regexes ( ( match ) NON-escaped \) parentheses) ONLY
</code></pre>
<hr />
<p dir="auto">In the <strong>new</strong> tab, you may perfectly <strong>spread</strong> over your text in <strong>many</strong> lines without any problem, as shown below :</p>
<pre><code class="language-diff">This 
( is (
 ( a very ) )
 small ( tes
 t \( to 
 ( verify \( 
if 
\)
 all ) ) these \)
  ( regexes ( 
 ( match ) NON-
escaped \)
 parentheses
) ONLY
</code></pre>
<p dir="auto">The regexes will still work ! Just <strong>one</strong> restriction : You cannot, of course, split an <strong>escaped</strong> parenthesis in <strong>two</strong> parts, like below :</p>
<pre><code>these \
)  ( regexes
</code></pre>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S.</strong> : Of course, if you change the <strong>starting</strong> position of the search, these <strong>recursive</strong> regular expressions will certainly find very <strong>different</strong> results in <strong>value</strong> and <strong>scope</strong> !</p>
</blockquote>
<p dir="auto">thanks for the awesome information.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/85678</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85678</guid><dc:creator><![CDATA[lossmark70]]></dc:creator><pubDate>Sat, 15 Apr 2023 11:23:43 GMT</pubDate></item><item><title><![CDATA[Reply to best way to stop matching of escaped parentheses/brackets in regular expression. on Sat, 01 Apr 2023 18:57:50 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><br />
Thanks! That’s a really cool solution. I think that Regex A will probably be most useful to me, so I bound it to a macro. This doesn’t really replace a lexer feature like I described, but it will still be helpful for sure.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/85394</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85394</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Sat, 01 Apr 2023 18:57:50 GMT</pubDate></item><item><title><![CDATA[Reply to best way to stop matching of escaped parentheses/brackets in regular expression. on Sun, 02 Apr 2023 12:37:03 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-olson" aria-label="Profile: mark-olson">@<bdi>mark-olson</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: ekopalypse">@<bdi>ekopalypse</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">There are a solution with <strong>recursive</strong> regexes ! Here are <strong><code>3</code></strong> kinds of <strong>recursive</strong> regex which do find <strong>paired</strong> groups of <strong>NON</strong>-escaped <strong>parentheses</strong> !</p>
<ul>
<li>
<p dir="auto">The regex <strong><code>A</code></strong> looks, from <strong>cursor</strong> position, for the <strong>greatest</strong> group of <strong>NON</strong>-escaped <strong>paired</strong> parentheses</p>
</li>
<li>
<p dir="auto">The regex <strong><code>B</code></strong> looks, from <strong>cursor</strong> position, for the <strong>greatest</strong> group of <strong>NON</strong>-escaped <strong>paired</strong> parentheses, <strong>surrounded</strong> by text <strong>different</strong> from <strong>NON</strong>-escaped parentheses</p>
</li>
<li>
<p dir="auto">The regex <strong><code>C</code></strong> looks, from <strong>cursor</strong> position, for the <strong>greatest</strong> range of characters, containing <strong>one</strong> or <strong>several</strong> group(s) of <strong>NON</strong>-escaped <strong>paired</strong> parentheses, each of them being <strong>surrounded</strong> by text <strong>different</strong> from <strong>NON</strong>-escaped parentheses</p>
</li>
<li>
<p dir="auto">Regex <strong><code>A</code></strong> : <strong><code>(?x) (?&lt;!\\) \( (?: (?: \\ [()] | [^()] ) | (?0) )* (?&lt;!\\) \)  # Regex A</code></strong></p>
</li>
<li>
<p dir="auto">Regex <strong><code>B</code></strong> : <strong><code>(?x) (?: \\ [()] | [^()] )* ( (?&lt;!\\) \( (?: (?: \\ [()] | [^()] ) | (?1) )* (?&lt;!\\) \) ) (?: \\ [()] | [^()] )*  # Regex B</code></strong></p>
</li>
<li>
<p dir="auto">Regex <strong><code>C</code></strong> : <strong><code>(?x) (?: (?: \\ [()] | [^()] )* ( (?&lt;!\\) \( (?: (?: \\ [()] | [^()] ) | (?1) )* (?&lt;!\\) \) ) (?: \\ [()] | [^()] )* )+  # Regex C</code></strong></p>
</li>
</ul>
<p dir="auto"><strong>Important</strong> : Sometimes the <strong>regex engine</strong> needs to go <strong>further</strong> on, in order to get a <strong>new paired</strong> group of parentheses to match !</p>
<hr />
<p dir="auto">To <strong>test</strong> these regexes,:</p>
<ul>
<li>
<p dir="auto"><strong>Paste</strong> the text below in a <strong>new</strong> tab</p>
</li>
<li>
<p dir="auto">Put the cursor , on the <strong>last</strong> line, <strong>right before</strong> the word <strong><code>This</code></strong></p>
</li>
<li>
<p dir="auto">Run, <strong>successively</strong>, the regexes <strong><code>A</code></strong>, <strong><code>B</code></strong> and <strong><code>C</code></strong></p>
</li>
</ul>
<pre><code class="language-diff">C     -------------------------------------------------------------------------- -----------------------------------------------------
B     ------------------------|------------------------------------------------- -----------------------------------------------------
A         --------------       --------------------------------------                     ---------------------------------------
     x    1 2        1 0       1            2                     1 0           x         1 2       1                           0
This ( is ( ( a very ) ) small ( test \( to ( verify \( if \) all ) ) these \)  ( regexes ( ( match ) NON-escaped \) parentheses) ONLY
</code></pre>
<hr />
<p dir="auto">In the <strong>new</strong> tab, you may perfectly <strong>spread</strong> over your text in <strong>many</strong> lines without any problem, as shown below :</p>
<pre><code class="language-diff">This 
( is (
 ( a very ) )
 small ( tes
 t \( to 
 ( verify \( 
if 
\)
 all ) ) these \)
  ( regexes ( 
 ( match ) NON-
escaped \)
 parentheses
) ONLY
</code></pre>
<p dir="auto">The regexes will still work ! Just <strong>one</strong> restriction : You cannot, of course, split an <strong>escaped</strong> parenthesis in <strong>two</strong> parts, like below :</p>
<pre><code>these \
)  ( regexes
</code></pre>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S.</strong> : Of course, if you change the <strong>starting</strong> position of the search, these <strong>recursive</strong> regular expressions will certainly find very <strong>different</strong> results in <strong>value</strong> and <strong>scope</strong> !</p>
]]></description><link>https://community.notepad-plus-plus.org/post/85391</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85391</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 02 Apr 2023 12:37:03 GMT</pubDate></item><item><title><![CDATA[Reply to best way to stop matching of escaped parentheses/brackets in regular expression. on Sat, 01 Apr 2023 08:47:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-olson" aria-label="Profile: Mark-Olson">@<bdi>Mark-Olson</bdi></a></p>
<p dir="auto">I think that bracket matching should only work on the grammar<br />
level of the main language, but yes, that would mean that every<br />
lexer would have to implement this. Of course, only if a grammar defines it.<br />
But that would also mean that in the above example the match group would not be highlighted.<br />
If this would be wanted, then the lexer has the problem that it<br />
must understand in which context a bracket is to be understood.<br />
What if a language allows to introduce a DSL (domain specific language) that brings its own syntax?<br />
The more I think about it the more difficult a general solution seems … but,<br />
then someone comes along, has a simple solution and gives the others the lie …<br />
A lot of text to say … no idea if this is easily possible.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/85384</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/85384</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Sat, 01 Apr 2023 08:47:40 GMT</pubDate></item></channel></rss>