<?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[Replacing a digit with exception]]></title><description><![CDATA[<p dir="auto">Hello everyone,<br />
I’m totally new here and also new to Notepad++ advanced usage.<br />
For many hours I tried to find a solution to my problem, without any clue and I hope there is a solution.</p>
<p dir="auto">I have a file with almost 9000 lines and I’d like to replace numbers with an exception.<br />
Here is an example of what the file looks like :</p>
<p dir="auto">dc.l	$02220620	; Tile #42<br />
dc.l	$01012021<br />
dc.l	$55111003	; Tile #956<br />
dc.l	$55001111<br />
dc.l	$54000116	; Tile #1628<br />
dc.l	$00022222</p>
<p dir="auto">Here, I want to replace all the digits “2”, except the ones that are after the sharp “#”.<br />
With my little experience, I didn’t go far, even trying to find a solution on the net.<br />
Is there a way to search and replace only in a specified string ? Like telling I want within the 8 characters string after the “$” or in everything befor the “;” ?<br />
Or could it be better just to search the “2” and make a replace with an exception (if we can) ?</p>
<p dir="auto">For example I tried this to avoid selecting after the “#” :<br />
(2)(.{1,8})<br />
Then replace with :<br />
\Q\2<br />
But it’s only replacing the first “2” and going to the next line…</p>
<p dir="auto">Any help would be welcomed :)<br />
Thank you</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20660/replacing-a-digit-with-exception</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 22:44:08 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20660.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 31 Jan 2021 01:15:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Replacing a digit with exception on Tue, 02 Feb 2021 17:56:33 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: jean-francois-trehard">@<bdi>jean-francois-trehard</bdi></a> and <em>All</em>,</p>
<p dir="auto">In wanting to <em>explain</em>, my regex S/R, provided in my <em>previous</em> post, I realized that we should add an <strong>hypothesis</strong> :</p>
<ul>
<li>You must move the <em>caret</em> to a <strong>blank</strong> line, located <strong>before</strong> the text to be processed by the <em>S/R</em></li>
</ul>
<p dir="auto">So, let’s start with the <em>last</em> version :</p>
<p dir="auto">SEARCH <strong><code>(?:\$|\G)\w*?\K(?:(0)|(1)|(2))</code></strong></p>
<p dir="auto">REPLACE <strong><code>(?1G)(?2H)(?3I)</code></strong></p>
<hr />
<ul>
<li>
<p dir="auto">Globally, the regex <strong><code>(?:\$|\G)\w*?\K(?:(0)|(1)|(2))</code></strong>, searches, from  after a <em>literal</em> <strong><code>$</code></strong> symbol OR after the <em>end</em> of the <em>previous</em> search, if any, for the <em>smallest</em> range, even <strong>empty</strong>, of <em>words</em> characters, till a <strong><code>0</code></strong>, <strong><code>1</code></strong> or <strong><code>2</code></strong> <em>digit</em>, then <em>only</em> selects this <strong>last</strong> digit and replaces it, respectively, with the <strong><code>G</code></strong>, <strong><code>H</code></strong> or <strong><code>I</code></strong> letters</p>
</li>
<li>
<p dir="auto">Note that the <strong><code>\G</code></strong> assertion forces the regex engine to ask itself : does the <em>current match</em> attempt, <strong>immediately</strong> follows the <em>previous</em> match ? In case of a <strong>positive</strong> answer, the <em>current match</em> attempt is a <em>possible</em> match, so far !</p>
</li>
<li>
<p dir="auto">As this regex <em>only</em> looks for <em>consecutive words</em> chars, it’s easy to understand why the characters, located, in the <em>second</em> part of a line, after the <strong><code>#</code></strong> sign, are <strong>not</strong> concerned !</p>
</li>
</ul>
<hr />
<p dir="auto">Now, if you’re still in the <em>fog</em>, let’s go into a little more <em>detail</em> and start the search, for instance, with <em>caret</em> on an <strong>empty</strong> line, right before the <em>first</em> line <strong><code>dc.l $02220620 ; Tile #42</code></strong></p>
<p dir="auto">Beware, everything below is a bit “<strong>off-putting</strong>” but, in any case, it happens like that if you break the process down into smaller <em>basic</em> actions !</p>
<hr />
<ul>
<li>
<p dir="auto">The regex engine <em>first</em> searches for a range of <em>consecutive words</em> characters till a <strong><code>0</code></strong>, <strong><code>1</code></strong> or <strong><code>2</code></strong> digit, either, after a <em>literal</em> <strong><code>$</code></strong> or after the <em>end</em> of the <em>previous</em> search. As <em>no</em> search has been performed, so far, <strong><code>\G</code></strong> syntax matches, by <em>default</em>, at <em>current</em> position, the beginning of the <em>empty</em> line, which is a <em>zero-length</em> string</p>
</li>
<li>
<p dir="auto">As <em>no word</em> char exists in that <em>empty</em> line, the regex engine <strong>skips</strong> the <strong><code>EOL</code></strong> chars and moves to the <em>beginning</em> of the <em>next</em> line <strong><code>dc.l $02220620 ; Tile #42</code></strong>. You could say : it should match the <strong><code>dc</code></strong> string, which are <em>word</em> chars, also ? No, no ! Because the <em>initial</em> location, in the <em>empty</em> line, and the <strong><code>dc</code></strong> location are <strong>not</strong> contiguous. Indeed, there is a gap of the <em>two</em> chars : <strong><code>\r</code></strong> and <strong><code>\n</code></strong> )</p>
</li>
<li>
<p dir="auto">Thus, the <strong><code>\G</code></strong> assertion is not <strong>true</strong>, presently. So the regex engine tries to match the <strong>first</strong> alternative and skips to the <em>literal</em> <strong><code>$</code></strong> and the <em>next</em> <strong><code>0</code></strong> digit to search for</p>
</li>
<li>
<p dir="auto">The <strong><code>\K</code></strong> feature <em>cancels</em> any match, so far and <em>resets</em> the regex engine <em>working</em> position =&gt; So, it only matches this first <strong><code>0</code></strong> <em>digit</em>. Remember that this configuration is possible as the range of chars <em>before</em> digit <strong><code>0</code></strong>, <strong><code>1</code></strong> or <strong><code>2</code></strong> to search for, may be <em>empty</em></p>
</li>
<li>
<p dir="auto">As the <em>group <code>1</code></em> is <em>defined</em>, when matching the <strong><code>0</code></strong> digit, the regex engine replaces it with the string <strong><code>G</code></strong></p>
</li>
<li>
<p dir="auto">Now, as <strong>no more</strong> <strong><code>$</code></strong> symbol exists, the regex engine needs to use the <strong>second</strong> alternative, the <strong><code>\G</code></strong> assertion, which represents the location right between the letter <strong><code>G</code></strong> and the <em>next</em> range of <em>word</em> chars till a <strong><code>0</code></strong>, <strong><code>1</code></strong> or <strong><code>2</code></strong> digit. So it just matches the <em>first</em> <strong><code>2</code></strong> digit, right after and, again, only selects that digit <strong><code>2</code></strong></p>
</li>
<li>
<p dir="auto">As the <em>group <code>3</code></em> is <em>defined</em> when matching the <strong><code>2</code></strong> digit, the regex engine replaces it with the string <strong><code>I</code></strong></p>
</li>
<li>
<p dir="auto">The <em>second</em>, <em>third</em> and <em>fourth</em> <strong><code>2</code></strong> digit, of current line, as well as the second <strong><code>0</code></strong> digit, are matched, in the <strong>same</strong> way as above, and replaced, consequently, with the <em>appropriate</em> letter</p>
</li>
<li>
<p dir="auto">Then, the regex engine matches the <strong><code>62</code></strong> digit, right after the <em>previous</em> <strong><code>G</code></strong> letter, which verifies the <strong><code>\G</code></strong> assertion and selects <em>only</em> the <em>fourth</em> digit <strong><code>2</code></strong> of current line, due to the <strong><code>\K</code></strong> syntax</p>
</li>
<li>
<p dir="auto">Again, this <strong><code>2</code></strong> digit is replaced with a <strong><code>I</code></strong> letter, as <em>group <code>3</code></em> is <em>defined</em> when matching the <strong><code>2</code></strong> digit</p>
</li>
<li>
<p dir="auto">The regex engine advances <em>one</em> position and matches the <em>last</em> <strong><code>0</code></strong> digit of current line and replaces it with the <strong><code>G</code></strong> letter</p>
</li>
<li>
<p dir="auto">Now, things become <em>interesting</em> : the regex engine must find a <em>next</em> range of <em>consecutive word</em> chars, possibly <em>empty</em>, ending with, either, a <strong><code>0</code></strong>, <strong><code>1</code></strong> or <strong><code>2</code></strong> digit. Obviously, this <em>next</em> range of <strong>contiguous</strong> <em>word</em> chars is the string <strong><code>42</code></strong>, located some chars <strong>after</strong> the end of our <em>previous</em> search ! So the <strong><code>\G</code></strong> assertion is <em>not</em> verified anymore and, as there is <em>no</em> other <strong><code>$</code></strong> symbol, either, the overall search <strong>fails</strong>. Thus, the regex engine skips the <strong>remaining</strong> chars of that <em>first</em> line, after the third <strong><code>0</code></strong> digit, which has been changed into <strong><code>G</code></strong> and <em>moves</em> to the <em>beginning</em> of the <strong>second</strong> line where the process <em>resumes</em> !</p>
</li>
<li>
<p dir="auto">And, when a line just ends with a <strong>first</strong> range of <em>word</em> chars, <em>without</em> any comments zone, it, necessarily, will search for a literal <strong><code>$</code></strong> symbol, as the <strong><code>\G</code></strong>  feature <strong>cannot</strong> be <em>true</em>, due to the <strong>gap</strong> produced by the <strong><code>EOL</code></strong> characters of <em>current</em> line !</p>
</li>
</ul>
<hr />
<p dir="auto">As you may notice, the <strong>key</strong> point, in this kind of data, is that, the <em>several</em> ranges of <em>words</em> characters are not <strong>juxtaposed</strong>. So, the <strong><code>\G</code></strong> assertion forces, <em>automatically</em>, the process to <em>cancel</em> any further search <em>after</em> examination of  each <em>first</em> range of <strong>consecutive words</strong> chars of each line, following a <strong><code>$</code></strong> symbol ;-))</p>
<p dir="auto">Note also that, due to the <strong><code>\K</code></strong> syntax, inside this <em>search</em> regex, you <em>cannot</em> use a <strong>step by step</strong> replacement with <em>several</em> clicks on the <strong><code>Replace</code></strong> button. However, you can use the <strong><code>Find Next</code></strong> button, to get the <em>different</em> matches</p>
<hr />
<p dir="auto">Wow ! Glad to see that you’re <strong>still</strong> there, after these <em>long</em> explanations ;-)) Thank you for your patience and <strong>full</strong> attention !</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62433</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62433</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Tue, 02 Feb 2021 17:56:33 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Mon, 01 Feb 2021 08:18:05 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>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a>,<br />
Thanks to both of you, this working great now !<br />
Have a nice day :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62397</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62397</guid><dc:creator><![CDATA[Jean-Francois Trehard]]></dc:creator><pubDate>Mon, 01 Feb 2021 08:18:05 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 23:12:54 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: jean-francois-trehard">@<bdi>jean-francois-trehard</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> and <strong>All</strong>,</p>
<p dir="auto"><strong>No</strong> problem too. We can do <strong>miracles</strong> with regexes ;-))</p>
<p dir="auto">This time :</p>
<ul>
<li>
<p dir="auto">We must use a <strong>non-capturing</strong> group at the <strong>very beginning</strong> of the regex</p>
</li>
<li>
<p dir="auto">We must add a <strong>second</strong> <strong>non-capturing</strong> group to get the <strong><code>\K</code></strong> feature for search of, either, the <strong>digits</strong> <strong><code>0</code></strong>, <strong><code>1</code></strong> or <strong><code>3</code></strong>, <strong>only</strong></p>
</li>
<li>
<p dir="auto">We must add <strong>inner</strong> real groups in order that :</p>
<ul>
<li>
<p dir="auto"><strong>Group</strong> <strong><code>1</code></strong> is <strong>defined</strong> when a <strong><code>0</code></strong> digit is matched</p>
</li>
<li>
<p dir="auto"><strong>Group</strong> <strong><code>2</code></strong> is <strong>defined</strong> when a <strong><code>1</code></strong> digit is matched</p>
</li>
<li>
<p dir="auto"><strong>Group</strong> <strong><code>3</code></strong> is <strong>defined</strong> when a <strong><code>2</code></strong> digit is matched</p>
</li>
</ul>
</li>
</ul>
<p dir="auto">And the replacement zone is <strong>self-explanatory</strong> !</p>
<p dir="auto">So, given this text :</p>
<pre><code class="language-diff">dc.l $02A20620 ; Tile #42
dc.l $0BaC2021
dc.l $55111003 ; Tile #9A56
dc.l $55001111
dc.l $54000116 ; Tile #1b628
dc.l $dF022222
</code></pre>
<p dir="auto">The following <strong>regex</strong> S/R :</p>
<p dir="auto">SEARCH <strong><code>(?:\$|\G)\w*?\K(?:(0)|(1)|(2))</code></strong></p>
<p dir="auto">REPLACE <strong><code>(?1G)(?2H)(?3I)</code></strong></p>
<p dir="auto">will output, in <strong>one</strong> pass, the <strong>expected</strong> text, leaving the comments <strong>untouched</strong></p>
<pre><code class="language-diff">dc.l $GIAIG6IG ; Tile #42
dc.l $GBaCIGIH
dc.l $55HHHGG3 ; Tile #9A56
dc.l $55GGHHHH
dc.l $54GGGHH6 ; Tile #1b628
dc.l $dFGIIIII
</code></pre>
<hr />
<p dir="auto">Again, if we use the <strong><code>(?x)</code></strong> modifier for the <strong>free-spacing</strong> behavior, the <strong>search</strong> regex becomes :</p>
<pre><code class="language-z">(?x)  (?: \$ | \G )  \w  *?  \K  (?:  (0) | (1) | (2)  )
</code></pre>
<p dir="auto">However, note that the <strong>replacement</strong> regex <strong>cannot</strong> be expressed with the <strong>free-spacing</strong> mode, but, for this <strong>specific</strong> replacement, the <strong>order</strong> of the <strong><code>(?#&lt;letter&gt;</code></strong> blocks does <strong>not</strong> matter !</p>
<p dir="auto">So, the <strong>replacement</strong> regex <strong><code>(?3I)(?2H)(?1G)</code></strong> would be <strong>correct</strong>, as well !</p>
<p dir="auto">BR</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62396</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62396</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 31 Jan 2021 23:12:54 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 22:55:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a> said in <a href="/post/62394">Replacing a digit with exception</a>:</p>
<blockquote>
<p dir="auto">(?1\1)(?2G)(?3H)(?4I)(?5J)(?6K)</p>
</blockquote>
<p dir="auto">Actually just thinking that you possibly need to change more than 9 groups (in total), the more correct coding would be:<br />
<code>(?{1}\1)(?{2}G)(?{3}H)(?{4}I)(?{5}J)(?{6}J)</code><br />
So this allows for lots of groups to be identified. In your case you would be using …<code>(?{10}X)(?{11}Y)(?{12}Z)</code> as an example.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62395</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62395</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 31 Jan 2021 22:55:00 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 22:47:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: Jean-Francois-Trehard">@<bdi>Jean-Francois-Trehard</bdi></a> said in <a href="/post/62392">Replacing a digit with exception</a>:</p>
<blockquote>
<p dir="auto">Do you know if we can do multiple replacements at once in Notepad++ ?</p>
</blockquote>
<p dir="auto">If you go with my regex, altered to cater for the different changes to be made you can do it ALL in 1 pass.</p>
<p dir="auto">So the new regex is<br />
Find What:<code>(?-s)(;.*$)|(0)|(1)|(2)|(3)|(4)</code><br />
Replace With:<code>(?1\1)(?2G)(?3H)(?4I)(?5J)(?6K)</code></p>
<p dir="auto">This is just an example as you have not provided ALL the changes you want, but the idea is the same. My regex can be extended to cater for as many characters as you want changed in the one run.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62394</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62394</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 31 Jan 2021 22:47:08 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 22:45:41 GMT]]></title><description><![CDATA[<p dir="auto">This is not working &gt;<br />
Find : (($|\G)\w*?\K0)|(($|\G)\w*?\K1)<br />
Replace : (?1G)(?2H)</p>
<p dir="auto">If I have 01001110, then I get GH1GHGH111GH</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62393</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62393</guid><dc:creator><![CDATA[Jean-Francois Trehard]]></dc:creator><pubDate>Sun, 31 Jan 2021 22:45:41 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 22:38:56 GMT]]></title><description><![CDATA[<p dir="auto">That is awsome, thank you. This is very complex for a pure beginner.<br />
Do you know if we can do multiple replacements at once in Notepad++ ?<br />
Like replacing all my 0 with G, all my 1 with H, etc, in one “Replace all”.<br />
I’m now checking it :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62392</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62392</guid><dc:creator><![CDATA[Jean-Francois Trehard]]></dc:creator><pubDate>Sun, 31 Jan 2021 22:38:56 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 22:42:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: jean-francois-trehard">@<bdi>jean-francois-trehard</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">Ah OK, I understood the <strong>problem</strong>. Actually, you meant that, once an <strong>S/R</strong> has been processed to replace, for instance, a <strong><code>2</code></strong> digit with the <strong><code>Q</code></strong> letter, a <strong>second</strong> search, for instance, of the <strong><code>6</code></strong> digit will <strong>not</strong> find <strong>all</strong> occurrences of the <strong><code>6</code></strong> digit, because the letter <strong><code>Q</code></strong> is <strong>not</strong> an <strong>hexadecimal</strong> number !</p>
<p dir="auto">Indeed, the regex must be changed as below :</p>
<p dir="auto">SEARCH <strong><code>(\$|\G)\w*?\K2</code></strong></p>
<p dir="auto">REPLACE <strong><code>Q</code></strong></p>
<hr />
<p dir="auto">BTW, note that we can, also, express the <strong>search</strong> regex, using the <strong>free-spacing</strong> mode <strong><code>(?x)</code></strong>, for a <strong>better</strong> readability :</p>
<pre><code class="language-z">(?x)   ( \$ | \G )   \w   *?   \K   2
</code></pre>
<hr />
<p dir="auto">Now, concerning the explanations, in my <strong>previous</strong> post, simply change any string “<strong>hexadecimal</strong> character” with the string “<strong>word</strong> character” !!</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
<p dir="auto"><strong>P.S.</strong></p>
<p dir="auto">I also think that my <strong>previous</strong> explanations need to be <strong>reread</strong>. I’ll see tomorrow  !</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62391</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62391</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 31 Jan 2021 22:42:17 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 22:01:55 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> oh I wrote something wrong :<br />
<s>“because it does not work if there are already digits in the 8 characteres strings”</s><br />
I meant  this : “because it does not work if there are already letters in the 8 characters strings”</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62390</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62390</guid><dc:creator><![CDATA[Jean-Francois Trehard]]></dc:creator><pubDate>Sun, 31 Jan 2021 22:01:55 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 21:49:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: jean-francois-trehard">@<bdi>jean-francois-trehard</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">I don’t understand ! In the <strong>picture</strong> showing the text, below, I added some <strong>pure hexadecimal</strong> characters, either, in <strong>lower</strong> or <strong>upper</strong> case, in many locations, even after the <strong><code>; Tile #</code></strong> string. Seemingly, all <strong><code>2</code></strong> digits, before <strong>comments</strong> only, are <strong>correctly</strong> marked !?</p>
<pre><code class="language-diff">dc.l $02A20620 ; Tile #42
dc.l $0BaC2021
dc.l $55111003 ; Tile #9A56
dc.l $55001111
dc.l $54000116 ; Tile #1b628
dc.l $dF022222
</code></pre>
<p dir="auto"><img src="/assets/uploads/files/1612129748437-d17bf642-4fa1-4ba9-9a34-944d1d906ea5-image.png" alt="d17bf642-4fa1-4ba9-9a34-944d1d906ea5-image.png" class=" img-fluid img-markdown" /></p>
<hr />
<p dir="auto"><strong>Jean-françois</strong>, could you <strong>provide</strong> some text which breaks the <strong>logic</strong> down ?</p>
<p dir="auto">BR</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62389</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62389</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 31 Jan 2021 21:49:44 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 21:32:17 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> merci.<br />
I’m going to read this carefully.<br />
Actually I have to change your following code (?-s)($|\G)[[:xdigit:]]*?\K2 because it does not work if there are already digits in the 8 characteres strings : the search is going to the next line each time it encounters a letter, even if it didn’t red the entire string.<br />
I have to scratch my head a little bit to try to find a solution, I’ll tell you if I find a solution :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62388</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62388</guid><dc:creator><![CDATA[Jean-Francois Trehard]]></dc:creator><pubDate>Sun, 31 Jan 2021 21:32:17 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 21:17:50 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: jean-francois-trehard">@<bdi>jean-francois-trehard</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">In wanting to explain, the <strong>search</strong> regex, provided in my <strong>previous</strong> post, I realized that we should add an <strong>hypothesis</strong> :</p>
<ul>
<li>You must move the <strong>caret</strong> to a <strong>blank</strong> line, located <strong>before</strong> the text to be processed by the <strong>S/R</strong></li>
</ul>
<hr />
<ul>
<li>
<p dir="auto">Globally, the regex <strong><code>(\$|\G)[[:xdigit:]]*?\K2</code></strong>, searches, from  after a <strong>literal</strong> <strong><code>$</code></strong> symbol OR after the <strong>end</strong> of the <strong>previous</strong> search, if any, for the <strong>smallest</strong> range, even null, of <strong>hexadecimal</strong> characters, till a <strong><code>2</code></strong> <strong>digit</strong> and <strong>only</strong> selects that digit <strong><code>2</code></strong> !</p>
</li>
<li>
<p dir="auto">Note that the <strong><code>\G</code></strong> assertion forces the regex engine to ask itself : does the <strong>current match</strong> attempt, <strong>immediately</strong> follows the <strong>previous</strong> match ? In case of a <strong>positive</strong> answer, the <strong>current match</strong> attempt is a <strong>possible</strong> match, so far.</p>
</li>
<li>
<p dir="auto">As this regex <strong>only</strong> looks for <strong>hexadecimal</strong> chars, it’s easy to understand why digits, located, in the <strong>second</strong> part of a line, after the <strong><code>#</code></strong>, are <strong>not</strong> concerned !</p>
</li>
</ul>
<hr />
<p dir="auto">Now, if you’re still in the <strong>fog</strong>, let’s go into a little more <strong>detail</strong> and start the search, for instance, with caret on an <strong>empty</strong> line, before the <strong>first</strong> line <strong><code>dc.l $02220620 ; Tile #42</code></strong> to process.</p>
<p dir="auto">All the stuff, below, is a bit <strong>off-putting</strong> but it goes like this, if you break the process down into more <strong>basic</strong> actions !</p>
<hr />
<ul>
<li>
<p dir="auto">The regex engine <strong>first</strong> searches for a range of <strong>hexadecimal</strong> characters, either, after a *<em>literal</em> <strong><code>$</code></strong> or after the <strong>end</strong> of the <strong>previous</strong> search. As <strong>no</strong> search has been performed so far, <strong><code>\G</code></strong> syntax matches, by <strong>default</strong>, at <strong>current</strong> position, the beginning of the <strong>empty</strong> line, which is a <strong>zero-length</strong> string</p>
</li>
<li>
<p dir="auto">But, <strong>no hexadecimal</strong> char exists in that <strong>empty</strong> line, so the regex engine skips the <strong><code>EOL</code></strong> chars and moves to the <strong>beginning</strong> of the <strong>next</strong> line <strong><code>dc.l $02220620 ; Tile #42</code></strong>. You could say : it will match the <strong><code>dc</code></strong> string, which are <strong>hexadecimal</strong> chars, also ? No, no ! Because the <strong>initial</strong> location, in the <strong>empty</strong> line, and the <strong><code>dc</code></strong> location are <strong>not</strong> contiguous. Indeed, there is the gap of the <strong>two</strong> chars : <strong><code>\r</code></strong> and <strong><code>\n</code></strong> )</p>
</li>
<li>
<p dir="auto">So, <em>necessarily</em>, the regex engine moves forward, <strong><code>3</code></strong> positions and, finally, matches the <strong>first</strong> alternative, the <strong>literal</strong> <strong><code>$</code></strong> , as well as the <strong><code>0</code></strong> and the first <strong><code>2</code></strong> digit</p>
</li>
<li>
<p dir="auto">The <strong><code>\K</code></strong> feature <strong>cancels</strong> any match, so far and <strong>resets</strong> the regex engine <strong>working</strong> position =&gt; So, it only matches the first <strong><code>2</code></strong> <strong>digit</strong> and replace it with the string <strong><code>Q</code></strong></p>
</li>
<li>
<p dir="auto">Now, as no more <strong><code>$</code></strong> symbol exists, the regex engine needs to use the <strong><code>\G</code></strong> assertion, which represents the location right between the string <strong><code>Q</code></strong> and the next <strong><code>2</code></strong> digit. As the <strong>hexadecimal</strong> range of chard, before a next <strong><code>2</code></strong>, may be <strong>null</strong>, the regex engine just matches this <strong>empty</strong> zone and the <strong>second</strong> <strong><code>2</code></strong> digit and, again, selects only the digit <strong><code>2</code></strong> and replaces it with the <strong><code>Q</code></strong> string</p>
</li>
<li>
<p dir="auto">The third <strong><code>2</code></strong> of current line is matched in the <strong>same</strong> way as above and replaced with the letter <strong><code>Q</code></strong></p>
</li>
<li>
<p dir="auto">Then, the regex engine matches the range of <strong>hexadecimal</strong> chars <strong><code>062</code></strong>, right after the <strong><code>Q</code></strong> letter, which verifies the <strong><code>\G</code></strong> assertion and selects <strong>only</strong> the <strong>fourth</strong> digit <strong><code>2</code></strong> of current line, due to the <strong><code>\K</code></strong> syntax and, again, replaces it with a <strong><code>Q</code></strong> letter</p>
</li>
<li>
<p dir="auto">Now, things become <strong>interesting</strong> : the regex engine must find a <strong>next</strong> range of <strong>hexadecimal</strong> chars, possibly <strong>null</strong>, ending with a <strong><code>2</code></strong> digit. But this <strong>next</strong> range of contiguous <strong>hexa</strong> chars is the string <strong><code>42</code></strong>, located some chars <strong>after</strong> the end of the <strong>previous</strong> search ! So the <strong><code>\G</code></strong> assertion is <strong>not</strong> verified anymore and, as there is no other <strong><code>$</code></strong> symbol, either, the overall search <strong>fails</strong> Thus, the regex engine skips the <strong>remaining</strong> chars of that <strong>first</strong> line and <strong>moves</strong> to <strong>beginning</strong> of the <strong>second</strong> line and the process resumes !</p>
</li>
<li>
<p dir="auto">And, if a line just ends with a <strong>first</strong> range of <strong>hexadecimal</strong> chars, it will search, next, for a literal <strong><code>$</code></strong> symbol, as the <strong><code>\G</code></strong>  feature is not <strong>true</strong>, due to the <strong>gap</strong> of the <strong><code>EOL</code></strong> characters of <strong>current</strong> line</p>
</li>
</ul>
<hr />
<p dir="auto">As you may notice, the <strong>key</strong> point, in that story, is that, when <strong>several</strong> ranges of <strong>hexadecimal</strong> characters exist, throughout a line, these are not <strong>juxtaposed</strong>. So, the <strong><code>\G</code></strong> assertion forces, <em>automatically</em>, the process to <strong>cancel</strong> any search <strong>after</strong> examination of  each <strong>first</strong> range of <strong>hexadecimal</strong> chars of each line ;-))</p>
<p dir="auto">Wow ! Glad to see that you’re <strong>still</strong> there, after these <strong>long</strong> explanations ;-)) Thank you for your patience and <strong>full</strong> attention !</p>
<hr />
<p dir="auto">Jean-François, je n’ai pas trop envie de reprendre tout ce laius, en français ;-) Si, certains points te paraîssent encore <strong>obscurs</strong>, je pourrais toujours t’aider, <strong>ultérieurement</strong> !</p>
<p dir="auto">Best regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62385</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62385</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 31 Jan 2021 21:17:50 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 17:14:15 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> It works great, thank you, no more issue before the $ :)<br />
I now have to understand and learn all what you both showed to me.</p>
<p dir="auto">De manière générale, je souhaite juste pouvoir remplacer 1 même caractère par un autre dans toutes les chaînes de 8 caractères juste après le “$” de mon fichier, qui fait au total presque 9000 lignes. Les caractères peuvent aller de 0 à 9 et de A à F.<br />
Ta dernière réponse m’a permis de ne plus avoir de souci avant le $, super :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62376</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62376</guid><dc:creator><![CDATA[Jean-Francois Trehard]]></dc:creator><pubDate>Sun, 31 Jan 2021 17:14:15 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 14:01:16 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: jean-francois-trehard">@<bdi>jean-francois-trehard</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-R">@<bdi>terry-R</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">I still do <strong>not</strong> understand exactly what you want to replace the number 2 with. Do you need to insert <strong>backslashes</strong> <strong><code>\</code></strong>, too, in replacement ?</p>
<p dir="auto">Seeing the <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a> answer, it seems that you want to replace any <strong>allowed</strong> <strong><code>2</code></strong> digit with the <strong><code>Q</code></strong> letter. Am I right about it ?</p>
<p dir="auto">Now, if you want to deal with <strong>hexadecimal</strong> numbers, no problem !</p>
<p dir="auto">Use the following <strong>regex</strong> S/R :</p>
<p dir="auto">SEARCH <strong><code>(\$|\G)[[:xdigit:]]*?\K2</code></strong></p>
<p dir="auto">REPLACE <strong><code>Q</code></strong></p>
<p dir="auto">Next time, if needed, I could give you some <strong>explanations</strong> about this S/R !</p>
<p dir="auto">Best regards,</p>
<p dir="auto">guy038</p>
<hr />
<p dir="auto">Je n’ai toujours <strong>pas</strong> compris, exactement, par quoi tu veux remplacer le <strong>chiffre</strong> <strong><code>2</code></strong>. As-tu besoin d’insérer des <strong>anti-slashes</strong>, également, dans le remplacement ?</p>
<p dir="auto">En voyant la réponse de <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-r">@<bdi>terry-r</bdi></a>, je suppose que tu désires remplacer chaque chiffre <strong><code>2</code></strong>, <strong>permis</strong>, par la <strong>lettre</strong> <strong><code>Q</code></strong>. Ai-je raison, à ce propos ?</p>
<p dir="auto">Maintenant, si tu veux chercher des chiffes <strong>héxadecimaux</strong>, no problem !</p>
<p dir="auto">Utilises la S/R suivante :</p>
<p dir="auto">CHERCHE <strong><code>(\$|\G)[[:xdigit:]]*?\K2</code></strong></p>
<p dir="auto">REMPLACE <strong><code>Q</code></strong></p>
<p dir="auto">La prochaine fois, si besoin, je pourrais te donner quelques <strong>explications</strong> sur cette S/R !</p>
<p dir="auto">Bien cordialement,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62370</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62370</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 31 Jan 2021 14:01:16 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 12:44:54 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> oui, je suis français :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62366</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62366</guid><dc:creator><![CDATA[Jean-Francois Trehard]]></dc:creator><pubDate>Sun, 31 Jan 2021 12:44:54 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 12:44:05 GMT]]></title><description><![CDATA[<p dir="auto">Oh many thanks to both of you !!! I’ll manage to understand all your scripts.</p>
<p dir="auto">My intention is to be able to change the same digit in all the 8 characters strings after the “$” with another digit.<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a>, it works great.<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/guy038" aria-label="Profile: guy038">@<bdi>guy038</bdi></a>, in your example, the result is adding a “Q” befor the “2” and not replacing it.</p>
<ul>
<li>I’ll also try to add the condition to find only after the “$” because the data in those 8 characters strings can be from 0 to F (in hexadecimal) and before this “$” we have the characters C and D.</li>
</ul>
<p dir="auto">Have a nice day :)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62365</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62365</guid><dc:creator><![CDATA[Jean-Francois Trehard]]></dc:creator><pubDate>Sun, 31 Jan 2021 12:44:05 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 12:21:13 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: jean-francois-trehard">@<bdi>jean-francois-trehard</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: terry-R">@<bdi>terry-R</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">If your need is to search for any <strong><code>2</code></strong> <strong>digit</strong>, in the <strong>first</strong> range of <strong>consecutive</strong> digits, after the <strong><code>$</code></strong> symbol, and replace it with the string <strong><code>Q2</code></strong>, a possible <strong><code>regex</code></strong> S/R would be :</p>
<p dir="auto">SEARCH <strong><code>(\$|\G)\d*?\K2</code></strong></p>
<p dir="auto">REPLACE <strong><code>Q2</code></strong></p>
<p dir="auto">So, from your <strong>sample</strong></p>
<pre><code class="language-diff">dc.l $02220620 ; Tile #42
dc.l $01012021
dc.l $55111003 ; Tile #956
dc.l $55001111
dc.l $54000116 ; Tile #1628
dc.l $00022222
</code></pre>
<p dir="auto">we get this text :</p>
<pre><code class="language-diff">dc.l $0Q2Q2Q206Q20 ; Tile #42
dc.l $0101Q20Q21
dc.l $55111003 ; Tile #956
dc.l $55001111
dc.l $54000116 ; Tile #1628
dc.l $000Q2Q2Q2Q2Q2
</code></pre>
<p dir="auto">As you can see, the <strong>digits</strong> <strong><code>2</code></strong> have <strong>not</strong> been changed <strong>after</strong> any <strong><code>; tile #</code></strong> area. Do you <strong>expect</strong> this output ?</p>
<hr />
<p dir="auto">By the way, are you <strong>French</strong> ? If so, next time, I could answer in <strong>both</strong> languages ;-)</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62364</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62364</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Sun, 31 Jan 2021 12:21:13 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 04:49:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/terry-r" aria-label="Profile: Terry-R">@<bdi>Terry-R</bdi></a> said in <a href="/post/62358">Replacing a digit with exception</a>:</p>
<blockquote>
<p dir="auto">Find What:(?-s)(;.*\R)|(2)</p>
</blockquote>
<p dir="auto">A minor refinement due to possibility of last line having the <code>; Tile # xxx</code> string. Currently my regex would replace any 2 in the Tile number. So replacement Find What is <code>(?-s)(;.*$)|(2)</code>. Note I replaced the <code>\R</code> with the <code>$</code> only.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62360</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62360</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 31 Jan 2021 04:49:57 GMT</pubDate></item><item><title><![CDATA[Reply to Replacing a digit with exception on Sun, 31 Jan 2021 02:03:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jean-francois-trehard" aria-label="Profile: Jean-Francois-Trehard">@<bdi>Jean-Francois-Trehard</bdi></a> said in <a href="/post/62355">Replacing a digit with exception</a>:</p>
<blockquote>
<p dir="auto">Here, I want to replace all the digits “2”, except the ones that are after the sharp “#”.</p>
</blockquote>
<p dir="auto">I wasn’t sure what you intended replacing the <code>2</code> with so I included the <code>Q</code> character, I know it’s obviously not what you want, so replace that character with what you need to in the “Replace With” field, or if nothing then just remove the <code>Q</code> character.</p>
<p dir="auto">So in essence we are looking for a <code>;</code> followed by some more characters until the end of the line. This search occurs at every character encountered, so if the current character(s) do not match then the regex uses the ‘alternate’ option, find a <code>2</code>. This allows it to move across the line character by character. Once it encounters the <code>;</code>, it grabs the remainder of the line and returns that. When it finds the 2, it currently replaces with a Q.<br />
So this means it can never encounter a 2 past the <code>;</code> in the line as the first portion of regex will be true and that takes precedence.</p>
<p dir="auto">Using the “Replace” function we have<br />
Find What:<code>(?-s)(;.*\R)|(2)</code><br />
Replace With:<code>(?1\1)(?2Q)</code></p>
<p dir="auto">Hopefully this solves your issue and the description I provided will help you understand the logic behind it.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/62358</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/62358</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Sun, 31 Jan 2021 02:03:03 GMT</pubDate></item></channel></rss>