<?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[is regex condition possible in replace-string]]></title><description><![CDATA[<p dir="auto">I convert genealogic indexes from archive-sites into a ged-file, so they can be imported in my genealogic program.</p>
<p dir="auto">In the searchstring I have made a named expression called (?&lt;CTNOTE&gt;…). In some cases it is possible that the CTNOTE expression is an empty string.</p>
<p dir="auto">So I want to insert the lines 2 NOTE @N01@ and 0 @N10@ NOTE $+{CTNOTE} in the replaced result text only when the CTNOTE expression is not empty. Is it possible to write an replace-regex that does this job and how is it written down?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/14208/is-regex-condition-possible-in-replace-string</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 10:55:24 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/14208.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Jul 2017 20:51:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to is regex condition possible in replace-string on Thu, 27 Jul 2017 20:28:40 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jos-maas" aria-label="Profile: jos-maas">@<bdi>jos-maas</bdi></a>,</p>
<p dir="auto">Oh yes ! You’re perfectly <strong>right</strong>. Even, in the example, described in my <strong>previous</strong> post, we don’t need any <strong>alternative</strong> !</p>
<p dir="auto">But, in that case, when a line does <strong>not</strong> match ( <strong>NO</strong> group <strong>jos</strong> ), this line stays <strong>unchanged</strong>, and we do <strong>not</strong> need, either, the <strong>ELSE</strong> part of the <strong>conditional</strong> replacement !</p>
<p dir="auto">So, the <strong>previous</strong> regex S/R, becomes :</p>
<p dir="auto">SEARCH <strong><code>(?-s)(?&lt;jos&gt;^\d+$)</code></strong></p>
<p dir="auto">REPLACE <strong><code>?{jos}Rewrite $+{jos}, as Group 'jos' exists</code></strong></p>
<p dir="auto">And, with the <strong>original</strong> text :</p>
<pre><code class="language-diff">123
This is a test
4567890
</code></pre>
<p dir="auto">We would get, this time, the text :</p>
<pre><code class="language-diff">Rewrite 123, as Group 'jos' exists
This is a test
Rewrite 4567890, as Group 'jos' exists
</code></pre>
<p dir="auto">Note that, in <strong>replacement</strong>, the <strong>outer</strong> parentheses are <strong>removed</strong>, without any problem !</p>
<hr />
<p dir="auto"><strong>Jos</strong>, for further information, about <strong>regular</strong> expressions <strong>concept</strong> and <strong>syntax</strong>, begin with that article, in <strong>N++ Wiki</strong> :</p>
<p dir="auto"><a href="http://docs.notepad-plus-plus.org/index.php/Regular_Expressions" rel="nofollow ugc">http://docs.notepad-plus-plus.org/index.php/Regular_Expressions</a></p>
<p dir="auto">In addition, you’ll find <strong>good documentation</strong>, about the <strong>Boost C++ Regex library, v1.55.0</strong> ( similar to the <strong>PERL Regular Common Expressions, v1.48.0</strong> ), used by <strong><code>Notepad++</code></strong>, <em>since its <strong><code>6.0</code></strong> version</em>, at the <strong>TWO</strong> addresses below :</p>
<p dir="auto"><a href="http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html" rel="nofollow ugc">http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html</a></p>
<p dir="auto"><a href="http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html" rel="nofollow ugc">http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html</a></p>
<ul>
<li>
<p dir="auto">The <strong>FIRST</strong> link explains the <strong>syntax</strong>, of regular expressions, in the <strong>SEARCH</strong> part</p>
</li>
<li>
<p dir="auto">The <strong>SECOND</strong> link explains the <strong>syntax</strong>, of regular expressions, in the <strong>REPLACEMENT</strong> part</p>
</li>
</ul>
<hr />
<p dir="auto">You may, also, look for <strong>valuable</strong> informations, on the <strong>sites</strong>, below :</p>
<p dir="auto"><a href="http://www.regular-expressions.info" rel="nofollow ugc">http://www.regular-expressions.info</a>  ( The <strong>reference</strong> !! )</p>
<p dir="auto"><a href="http://www.rexegg.com" rel="nofollow ugc">http://www.rexegg.com</a></p>
<p dir="auto"><a href="http://perldoc.perl.org/perlre.html" rel="nofollow ugc">http://perldoc.perl.org/perlre.html</a></p>
<p dir="auto">Be aware that, as any <strong>documentation</strong>, it may contain some <strong>errors</strong> ! Anyway, if you detected one, that’s <strong>good news</strong> : you’re improving ;-)</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/25918</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25918</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 27 Jul 2017 20:28:40 GMT</pubDate></item><item><title><![CDATA[Reply to is regex condition possible in replace-string on Wed, 26 Jul 2017 14:47:26 GMT]]></title><description><![CDATA[<p dir="auto">Bonjour, Guy038,</p>
<p dir="auto">Your help was to the point, as showed by snippets from the search and replace string hereafter.</p>
<p dir="auto">In the searchstring: (Opmerking\R+(?&lt;CTOPM&gt;[A-z ]*$)\R+) - there is no need to have an alternation operator and string, because there is a match if “Opmerking\R” is in the tekst and the CTOPM-named substring is not empty, or not.</p>
<p dir="auto">The replacestrings: (?{CTOPM}2 NOTE @N10@\r\n:) and (?{CTOPM}0 @N10@ NOTE $+{CTOPM}\r\n:) generate the wanted lines if there is a match, or do nothing if there is no match.</p>
<p dir="auto">This item and that in my previous post illustrate the problem that I have as a newby in regex matters. As I know from my studies - some fifty years ago - you need basic theory, advanced theory and applied theory books to learn a job. I feel there is a lack specific for the regex in notepad++. The tutorial could be seen as an applied handbook, your “SYNTAXE des expressions RÉGULIÈRES PRCE, de NOTEPAD++ v6.0 et PLUS” is perhaps advanced theory, but - as far as I can see - both don’t give a complete overview of all aspects of the regex in notepad++. So far your replies on my posts provide the needed information in addition.</p>
<p dir="auto">I am grateful for your help on both my posts and I surely will write a call for help when I encounter a new problem.</p>
<p dir="auto">Cordialement, Jos</p>
]]></description><link>https://community.notepad-plus-plus.org/post/25882</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25882</guid><dc:creator><![CDATA[Jos Maas]]></dc:creator><pubDate>Wed, 26 Jul 2017 14:47:26 GMT</pubDate></item><item><title><![CDATA[Reply to is regex condition possible in replace-string on Tue, 25 Jul 2017 22:47:43 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jos-maas" aria-label="Profile: jos-maas">@<bdi>jos-maas</bdi></a> and <strong>All</strong></p>
<p dir="auto">Sorry, I didn’t understand, exactly, what string must <strong>replace</strong> your matched <strong>search</strong>, but here is the <strong>general</strong> description of the  <strong>back-references</strong> and <strong>conditional</strong> replacements syntaxes, in the <strong>REPLACE</strong> part, when using <strong>named</strong> groups :</p>
<p dir="auto">SEARCH <strong><code>(?-s)(?&lt;jos&gt;^\d+$)|.+</code></strong></p>
<p dir="auto">REPLACE <strong><code>(?{jos}Rewrite $+{jos}, as Group 'jos' exists:Group 'jos' does NOT exist !)</code></strong></p>
<p dir="auto">With the reges S/R, above, the text :</p>
<pre><code class="language-diff">123
This is a test
4567890
</code></pre>
<p dir="auto">would be <strong>changed</strong> into :</p>
<pre><code class="language-diff">Rewrite 123, as Group 'jos' exists
Group 'jos' does NOT exist !
Rewrite 4567890, as Group 'jos' exists
</code></pre>
<hr />
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">As usual, the <strong><code>(?-s)</code></strong> part is added to be sure that the <strong>dot</strong> symbol will match <strong>standard</strong> characters, only !</p>
</li>
<li>
<p dir="auto">Then we’re searching, <strong>either</strong> :</p>
<ul>
<li>
<p dir="auto">A <strong>single integer</strong> number, per line, stored as group <strong>jos</strong> <strong><code>(?&lt;jos&gt;^\d+$)</code></strong> ( It’s the <strong>priority</strong> search, as the <strong>first</strong> branch of the <strong>alternative</strong> )</p>
</li>
<li>
<p dir="auto"><strong>All  NON-empty</strong> contents of <strong>current</strong> line <strong><code>.+</code></strong></p>
</li>
</ul>
</li>
<li>
<p dir="auto">In <strong>replacement</strong>, we use the <strong>conditional</strong> replacement <strong><code>(?{jos}++++++++:--------)</code></strong>, which means :</p>
<ul>
<li>
<p dir="auto">If the group <strong>jos</strong> exists, we rewrite the <strong>++++++++</strong> text ( part <strong>before</strong> the <strong>colon</strong> symbol )</p>
</li>
<li>
<p dir="auto">If the group <strong>jos</strong> does <strong>not</strong> exist, we rewrite the <strong>--------</strong> text ( part <strong>after</strong> the <strong>colon</strong>  symbol )</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">So :</p>
<ul>
<li>
<p dir="auto">If a line contains a <strong>single number</strong>, the group <strong>jos</strong> exists and we re-write <strong><code>Rewrite $+{jos}, as Group 'jos' exists</code></strong>, with <strong><code>$+{jos</code></strong>, being a <strong>back-reference</strong> to the <strong>named</strong> group <strong>jos</strong></p>
</li>
<li>
<p dir="auto">ELSE the group <strong>jos</strong> does <strong>not</strong> exist and we, simply, rewrite the <strong>literal</strong> text, located after the <strong>colon</strong> symbol  <strong><code>Group 'jos' does NOT exist !</code></strong></p>
</li>
</ul>
<p dir="auto">I <strong>do</strong> hope that this simple example will help you to <strong>solve</strong> your problem, easily !</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/25867</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25867</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 25 Jul 2017 22:47:43 GMT</pubDate></item><item><title><![CDATA[Reply to is regex condition possible in replace-string on Tue, 25 Jul 2017 21:29:46 GMT]]></title><description><![CDATA[<p dir="auto">Again, this is more a RegEx related question.<br />
There are several websites dedicated to RegEx, just google for it.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/25865</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/25865</guid><dc:creator><![CDATA[MAPJe71]]></dc:creator><pubDate>Tue, 25 Jul 2017 21:29:46 GMT</pubDate></item></channel></rss>