<?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[Regex alternation in both FIND & REPLACE strings]]></title><description><![CDATA[<p dir="auto">(I hereby swear that the advice requested in this post is intended for use specifically in Notepad++.)  :-)</p>
<p dir="auto">Not wanting an excellent suggestion to go to waste, I took special notice of the <a href="https://community.notepad-plus-plus.org/post/58246">recent post</a> by <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> in which he provided an example of using regex alternation in both <strong>FIND</strong> and <strong>REPLACE</strong> strings, which I’d never seen done before. I found an opportunity to give it a try here, but it didn’t quite work out the way I intended. The following example text shows what it looks like <strong>before</strong> my intended regex operation:</p>
<pre><code>1. “Track 1" (Outtake)	3:24
2. “Track 2" (Alternate Version)	3:30
3. “Track 3" (Drone Mix)	2:51
4. “Track 4" (Alternate Version)	4:08
5. “Track 5" (Rehearsal)	4:34
6. “Track 6" (Alternate Version)	3:34
7. “Track 7" (String Mix)	4:29
8. “Track 8" (Rehearsal)	1:40
9. “Track 9" (Alternate Version)	4:50
10. “Track 10" (Rehearsal)	2:52
11. “Track 11" (Piano Mix)	6:09
12. “Track 12" (unlisted instrumental)	5:17
</code></pre>
<p dir="auto">My regex expressions (with bold curly quotes added to help clarify the presence of leading and/or trailing spaces):</p>
<p dir="auto"><strong>FIND</strong>: <strong>“</strong><code>" ((\(Outtake\))|(\(Alternate Version\))|(\(Drone Mix\))|(\(Rehearsal\))|(\(String Mix\))|(\(Piano Mix\))|(\(unlisted instrumental\)))\t</code><strong>”</strong></p>
<p dir="auto"><strong>REPLACE</strong>: <strong>“</strong><code>((?1)(?2 [alt])(?3 [drone mix])(?4 [rehearsal])(?5 [string mix])(?6 [piano mix])(?7 [instrumental]))” — </code><strong>”</strong></p>
<p dir="auto">My intended result:</p>
<pre><code>1. “Track 1” — 3:24
2. “Track 2 [alt]” — 3:30
3. “Track 3 [drone mix]” — 2:51
4. “Track 4 [alt]” — 4:08
5. “Track 5 [rehearsal]” — 4:34
6. “Track 6 [alt]” — 3:34
7. “Track 7 [string mix]” — 4:29
8. “Track 8 [rehearsal]” — 1:40
9. “Track 9 [alt]” — 4:50
10. “Track 10 [rehearsal]” — 2:52
11. “Track 11 [piano mix]” — 6:09
12. “Track 12 [instrumental]” — 5:17
</code></pre>
<p dir="auto">My actual result:</p>
<pre><code>1. “Track 1 [alt]” — 3:24
2. “Track 2 [drone mix]” — 3:30
3. “Track 3 [rehearsal]” — 2:51
4. “Track 4 [drone mix]” — 4:08
5. “Track 5 [string mix]” — 4:34
6. “Track 6 [drone mix]” — 3:34
7. “Track 7 [piano mix]” — 4:29
8. “Track 8 [string mix]” — 1:40
9. “Track 9 [drone mix]” — 4:50
10. “Track 10 [string mix]” — 2:52
11. “Track 11 [instrumental]” — 6:09
12. “Macbeth” — 5:17
</code></pre>
<p dir="auto">Is there a trick I’m missing?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/20110/regex-alternation-in-both-find-replace-strings</link><generator>RSS for Node</generator><lastBuildDate>Fri, 09 Oct 2026 20:55:51 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/20110.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 07 Oct 2020 03:58:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regex alternation in both FIND & REPLACE strings on Wed, 07 Oct 2020 22:54:30 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/58351">Regex alternation in both FIND &amp; REPLACE strings</a>:</p>
<blockquote>
<p dir="auto">Ok, so you could refer to this link to get the <strong>main punctuation</strong> characters :</p>
<p dir="auto"><a href="https://www.unicode.org/charts/PDF/U2000.pdf" rel="nofollow ugc">https://www.unicode.org/charts/PDF/U2000.pdf</a></p>
</blockquote>
<p dir="auto">Thank. I’ll keep that in mind for if/when I ever need to use Unicode text on a large scale, though I’m not currently anticipating it will happen.</p>
<blockquote>
<p dir="auto">This means that the part <strong><code>"\x20\x{2014}\x20</code></strong>, at the <strong>end</strong>, is rewritten <strong>whatever</strong> group matches the search regex.</p>
</blockquote>
<p dir="auto">Ok, thanks for the detailed explanation and further suggestions as well. I will look for opportunities to apply them in future projects.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58362</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58362</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Wed, 07 Oct 2020 22:54:30 GMT</pubDate></item><item><title><![CDATA[Reply to Regex alternation in both FIND & REPLACE strings on Wed, 07 Oct 2020 20:26:15 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/m-andre-z-eckenrode" aria-label="Profile: m-andre-z-eckenrode">@<bdi>m-andre-z-eckenrode</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"><a class="plugin-mentions-user plugin-mentions-a" href="/user/m-andre-z-eckenrode" aria-label="Profile: m-andre-z-eckenrode">@<bdi>m-andre-z-eckenrode</bdi></a>, many thanks for your <strong>clear</strong> and fast reply ! Ok, so you could refer to this link to get the <strong>main punctuation</strong> characters :</p>
<p dir="auto"><a href="https://www.unicode.org/charts/PDF/U2000.pdf" rel="nofollow ugc">https://www.unicode.org/charts/PDF/U2000.pdf</a></p>
<p dir="auto">They belong to the Unicode <strong>General Punctuation</strong> block ( range <strong><code>U+0000 - U+206F</code></strong> ) Of course, <strong>most</strong> of them are <strong>repeated</strong> in common <strong>Windows</strong> encodings, from <strong><code>Windows-1250</code></strong>  till <strong><code>Windows-1258</code></strong>, with the input method <strong><code>Alt + 0###</code></strong> to write them in a text ! Refer to :</p>
<p dir="auto"><a href="https://en.wikipedia.org/wiki/Windows-1252#Character_set" rel="nofollow ugc">https://en.wikipedia.org/wiki/Windows-1252#Character_set</a></p>
<p dir="auto">Thus, just change the classical <strong><code>"</code></strong> char by the <strong><code>”</code></strong> character, or the syntax <strong><code>\x{201D}</code></strong>, in the <strong>search</strong> and <strong>replacement</strong> regexes !</p>
<hr />
<p dir="auto">Regarding the <strong>free-spacing</strong> mode ( <strong><code>(?x)</code></strong> ), <strong><code>4</code></strong> important points to remember :</p>
<ul>
<li>
<p dir="auto">In this mode, space(s) and line-break(s) are <strong>irrelevant</strong>. So if you need :</p>
<ul>
<li>
<p dir="auto">To search for a <strong>space</strong>, use the forms <strong><code>\x20</code></strong> or <strong><code>[ ]</code></strong> or <strong>escape</strong> the <strong>space</strong> char with the <strong><code>\</code></strong> character</p>
</li>
<li>
<p dir="auto">To search for a <strong>line-break</strong>, use, as usual, the <strong><code>\r\n</code></strong>, or <strong><code>\r</code></strong> or <strong><code>\n</code></strong> or the composite <strong><code>\R</code></strong> syntaxes</p>
</li>
</ul>
</li>
<li>
<p dir="auto">In this mode any <strong><code>#</code></strong> character begins a <strong>single-line comment</strong> zone. So, use the syntaxes <strong><code>\x23</code></strong>, <strong><code>\#</code></strong> or <strong><code>[#]</code></strong> to search for a <strong>literal</strong> <strong><code>#</code></strong> char</p>
</li>
<li>
<p dir="auto">In this mode, your may <strong>split</strong> your <strong>search</strong> regex in <strong>several</strong> lines for readability, <strong>commenting</strong> each line ! See, below.</p>
</li>
<li>
<p dir="auto">Unfortunately, this mode <strong>cannot</strong> be used for the <strong>Replace</strong> zone</p>
</li>
</ul>
<pre><code class="language-z">(?x)                          # FREE-SPACING mode
(?-si)                        # Any DOT matches a SINGLE STANDARD char, ONLY and the search process is SENSITIVE to case
"  \x20  \(                   # A DOUBLE-QUOTATION mark , a SPACE char and an OPENING PARENTHESIS
(?:                           # Start of a NON-CAPTURING group
  (Outtake)                   #   String "Outtake", STORED in group 1
|                             # OR
  (Alternate\x20Version)      #   String "Alternate\x20Version", STORED in group 2
|                             # OR
  (unlisted\x20instrumental)  #   String "unlisted instrumental", STORED in group 3
|                             # OR
  (.+?)                       #   The SMALLEST NON-NULL range of STANDARD characters, ... till an ENDING PARENTHESIS, STORED in group 4
                              #     ( It corresponds to the OTHER strings which JUST need to be REWRITTEN in LOWERCASE, during the REPLACEMENT phase )
)                             # End of the NON-CAPTURING group
\)  \t                        # An ENDING PARENTHESIS and a TABULATION char
</code></pre>
<p dir="auto">Just select <strong>all</strong> the lines and open the <strong><code>Search</code></strong> or <strong><code>Replace</code></strong> dialog !</p>
<hr />
<p dir="auto">Although <strong>NOT</strong> allowed in the <strong>replacement</strong> zone, here is the <strong>logic</strong> of the replacement :</p>
<pre><code class="language-z">(?1                         # CONDITIONAL replacement, based on EXISTENCE of group 1
                            #   Part THEN, before the COLON, EMPTY =&gt; SUPPRESSION of the string "Outtake"
:                           # ELSE ( for ANY group DIFFERENT from group 1 or anything NOT in a group )
  \x20  [                   #   A SPACE char and an OPENING SQUARED bracket are rewritten
  (?2alt)                   #   CONDITIONAL replacement, based on EXISTENCE of group 2 =&gt; The string "Alternate Version" is changed into "alt"
  (?3instrumental)          #   CONDITIONAL replacement, based on EXISTENCE of group 3 =&gt; The string "unlisted instrumental" is changed into "instrumental"
  (?4\L\4)                  #   CONDITIONAL replacement, based on EXISTENCE of group 4 =&gt; Any OTHER string is just REWRITTEN in LOWERCASE, due to the \L MODIFIER
  ]                         #   an ENDING SQUARED bracket is rewritten
)                           # End of the first CONDITIONAL replacement
"  \x20  \x{2014}  \x20     # A DOUBLE-QUOTATION mark, a SPACE char, an EM_DASH char and a final SPACE char are rewritten
</code></pre>
<p dir="auto">Allow me to repeat : the <strong>multi</strong>-lines replacement, right above, must <strong>NOT</strong> be used and is intended for <strong>explanations</strong> only !</p>
<hr />
<p dir="auto">You said :</p>
<blockquote>
<p dir="auto">I am still curious as to why my first attempted expressions, detailed in my previous post above</p>
</blockquote>
<p dir="auto">Well, let’s imagine the regex <strong><code>(ABC|DEF|XYZ)\d+</code></strong>. This regex is equivalent to the regex <strong><code>ABC\d+|DEF\d+|XYZ\d+</code></strong> which searches for strings <strong><code>ABC</code></strong>, <strong><code>DEF</code></strong> or <strong><code>XYZ</code></strong>, each, followed by, at least, one <strong>digit</strong></p>
<p dir="auto">But, of course, if you <strong>omit</strong> the parentheses, the regex <strong><code>ABC|DEF|XYZ\d+</code></strong> searches for the string <strong><code>ABC</code></strong> <em>OR</em> the string <strong><code>DEF</code></strong> <em>OR</em> the string <strong><code>XYZ</code></strong> followed by, at least, one <strong>digit</strong></p>
<hr />
<p dir="auto">Now , let’s try to <strong>simplify</strong> your <strong>search</strong> regex :</p>
<ul>
<li>Inside the <strong>non-capturing</strong> group <strong>each</strong> string is embedded with <strong><code>\(</code></strong> and <strong><code>\)</code></strong> =&gt; they could be placed <strong>outside</strong> the <strong>non-capturing</strong> group ( I use the <strong><code>\x20</code></strong> syntax for a <strong>space</strong>, in order to avoid your <strong>black bold</strong> notation ! )</li>
</ul>
<p dir="auto">=&gt; <strong><code>"\x20\((?:(Outtake)|(Alternate Version)|(Drone Mix)|(Rehearsal)|(String Mix)|(Piano Mix)|(unlisted instrumental))\)\t</code></strong></p>
<ul>
<li>In my search regex, note that I did <strong>not</strong> take in account the strings different from <strong>Outtake</strong>, <strong>Alternate Version</strong> and <strong>unlisted instrumental</strong>, as <strong>all</strong> the <strong>other</strong> strings, caught with the <strong><code>(.+?)</code></strong> syntax, are simply rewritten in <strong>lowercase</strong>, due to the <strong><code>\L</code></strong> replacement syntax</li>
</ul>
<p dir="auto">Your <strong>replacement</strong> regex may be <strong>simplified</strong>, too : the <strong>outer</strong> parentheses are <strong>useless</strong> :</p>
<p dir="auto">=&gt; <strong><code>(?1)(?2 [alt])(?3 [drone mix])(?4 [rehearsal])(?5 [string mix])(?6 [piano mix])(?7 [instrumental])\x{201D}\x20\x{2014}\x20</code></strong></p>
<p dir="auto">This means that the part <strong><code>"\x20\x{2014}\x20</code></strong>, at the <strong>end</strong>, is rewritten <strong>whatever</strong> group matches the search regex. In other words, it’s like this <strong>pseudo</strong> syntax <strong><code>(?*\x{201D}\x20\x{2014}\x20)</code></strong>, for <strong>any</strong> group, was possible !</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58351</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58351</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Wed, 07 Oct 2020 20:26:15 GMT</pubDate></item><item><title><![CDATA[Reply to Regex alternation in both FIND & REPLACE strings on Wed, 07 Oct 2020 15:29: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> said in <a href="/post/58334">Regex alternation in both FIND &amp; REPLACE strings</a>:</p>
<blockquote>
<p dir="auto">I noticed that your text is <strong>displayed</strong>, on our <strong>forum</strong>, with <strong>quotations</strong> characters <strong><code>“</code></strong> and <strong><code>”</code></strong> ( of <strong>Unicode</strong> code-points <strong><code>\x201C</code></strong> and <strong><code>\x201C</code></strong> ). And I suppose that your <strong>real</strong> text, <strong>before</strong> of <strong>after</strong> the regex operation, contains the usual <strong><code>"</code></strong> character ( <strong><code>\x22</code></strong> ), only !</p>
</blockquote>
<p dir="auto">Actually, I prefer and routinely use typographical (curly) quotation marks <code>“ ”</code> and <code>‘ ’</code> in text I’m editing, except when the straight variety <code>" "</code> and <code>' '</code> are required for any computer code purposes. But the vast majority of my text editing is done as ANSI/Windows-1252 rather than Unicode, so those code points are usually decimal 145–148, or hex 91–94 for me.</p>
<blockquote>
<p dir="auto">in the <strong>replacement</strong> part, seemingly, you use the <strong>EM DASH</strong> ( <strong><code>\x{2014}</code></strong> ) character, instead of the <strong>usual</strong> <strong><code>-</code></strong> char ( <strong><code>\x2d</code></strong> )</p>
</blockquote>
<p dir="auto">Also intentional, and sometimes I also use the <strong>EN DASH</strong> (decimal code points 150/151, or hex 96/97), as in my previous paragraph.</p>
<blockquote>
<p dir="auto">So this leads to the <strong>following</strong> regex S/R :</p>
<p dir="auto">SEARCH <strong><code>(?x-si) "\x20\( (?: (Outtake) | (Alternate\x20Version) | (unlisted\x20instrumental) | (.+?)  ) \)\t</code></strong></p>
<p dir="auto">REPLACE <strong><code>(?1:\x20[(?2alt)(?3instrumental)(?4\L\4)])"\x20\x{2014}\x20</code></strong></p>
</blockquote>
<p dir="auto">Of course, those only work for me if I’m using Unicode text, but I’m usually not, and, as noted above, my use of <code>“ ”</code> was intentional, though that would be easy enough to change in your suggested expressions.</p>
<blockquote>
<p dir="auto">Remark that I use the <strong>free-spacing</strong> mode <strong><code>(?x)</code></strong> in order to <strong>separate</strong> the different parts of the <strong>search</strong> regex for a <strong>better</strong> comprehension</p>
</blockquote>
<p dir="auto">Yes, noted. I’ll keep that in mind for possible future use.</p>
<blockquote>
<p dir="auto"><strong>Next</strong> time, I could explain these <strong>regex</strong> syntaxes, if you feel <strong>difficulties</strong> to understand them !</p>
</blockquote>
<p dir="auto">I think I’m good, but thanks! For the record, these are the working expressions I settled on (not counting the surrounding <strong>black bold “ ”</strong>):</p>
<p dir="auto"><strong>FIND</strong>: <strong>“</strong><code>" (?:(\(Outtake\))|(\(Alternate Version\))|(\(Drone Mix\))|(\(Rehearsal\))|(\(String Mix\))|(\(Piano Mix\))|(\(unlisted instrumental\)))\t</code><strong>”</strong></p>
<p dir="auto"><strong>REPLACE</strong>: <strong>“</strong><code>((?1)(?2 [alt])(?3 [drone mix])(?4 [rehearsal])(?5 [string mix])(?6 [piano mix])(?7 [instrumental]))” — </code><strong>”</strong></p>
<p dir="auto">I am still curious as to why my first attempted expressions, detailed in my <a href="https://community.notepad-plus-plus.org/post/58324">previous post above</a>, replaced the <code>"</code> in only the first line (<code>1. “Track 1" (Outtake)	3:24</code>), if you or anybody else has any idea.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58348</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58348</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Wed, 07 Oct 2020 15:29:05 GMT</pubDate></item><item><title><![CDATA[Reply to Regex alternation in both FIND & REPLACE strings on Wed, 07 Oct 2020 17:19:35 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/m-andre-z-eckenrode" aria-label="Profile: m-andre-z-eckenrode">@<bdi>m-andre-z-eckenrode</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>
<ul>
<li>
<p dir="auto">First, I noticed that your text is <strong>displayed</strong>, on our <strong>forum</strong>, with <strong>quotations</strong> characters <strong><code>“</code></strong> and <strong><code>”</code></strong> ( of <strong>Unicode</strong> code-points <strong><code>\x201C</code></strong> and <strong><code>\x201D</code></strong> ). And I suppose that your <strong>real</strong> text, <strong>before</strong> of <strong>after</strong> the regex operation, contains the usual <strong><code>"</code></strong> character ( <strong><code>\x22</code></strong> ), only !</p>
</li>
<li>
<p dir="auto">Secondly, in the <strong>replacement</strong> part, seemingly, you use the <strong>EM DASH</strong> ( <strong><code>\x{2014}</code></strong> ) character, instead of the <strong>usual</strong> <strong><code>-</code></strong> char ( <strong><code>\x2d</code></strong> )</p>
</li>
</ul>
<hr />
<p dir="auto">So this leads to the <strong>following</strong> regex S/R :</p>
<p dir="auto">SEARCH <strong><code>(?x-si) "\x20\( (?: (Outtake) | (Alternate\x20Version) | (unlisted\x20instrumental) | (.+?)  ) \)\t</code></strong></p>
<p dir="auto">REPLACE <strong><code>(?1:\x20[(?2alt)(?3instrumental)(?4\L\4)])"\x20\x{2014}\x20</code></strong></p>
<p dir="auto">So from the text :</p>
<pre><code class="language-diff">1. "Track 1" (Outtake)	3:24
2. "Track 2" (Alternate Version)	3:30
3. "Track 3" (Drone Mix)	2:51
4. "Track 4" (Alternate Version)	4:08
5. "Track 5" (Rehearsal)	4:34
6. "Track 6" (Alternate Version)	3:34
7. "Track 7" (String Mix)	4:29
8. "Track 8" (Rehearsal)	1:40
9. "Track 9" (Alternate Version)	4:50
10. "Track 10" (Rehearsal)	2:52
11. "Track 11" (Piano Mix)	6:09
12. "Track 12" (unlisted instrumental)	5:17
</code></pre>
<p dir="auto">We get the <strong>expected</strong> text, with usual <strong><code>"</code></strong> quotation and the <strong>EM Dash</strong> char <strong><code>—</code></strong> before each track’s <strong>duration</strong> :</p>
<pre><code class="language-diff">1. "Track 1" — 3:24
2. "Track 2 [alt]" — 3:30
3. "Track 3 [drone mix]" — 2:51
4. "Track 4 [alt]" — 4:08
5. "Track 5 [rehearsal]" — 4:34
6. "Track 6 [alt]" — 3:34
7. "Track 7 [string mix]" — 4:29
8. "Track 8 [rehearsal]" — 1:40
9. "Track 9 [alt]" — 4:50
10. "Track 10 [rehearsal]" — 2:52
11. "Track 11 [piano mix]" — 6:09
12. "Track 12 [instrumental]" — 5:17
</code></pre>
<p dir="auto">Remark that I use the <strong>free-spacing</strong> mode <strong><code>(?x)</code></strong> in order to <strong>separate</strong> the different parts of the <strong>search</strong> regex for a <strong>better</strong> comprehension</p>
<p dir="auto"><strong>Next</strong> time, I could explain these <strong>regex</strong> syntaxes, if you feel <strong>difficulties</strong> to understand them ! Presently, I’ve got some <strong>other</strong> posts to reply to  ;-))</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58334</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58334</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Wed, 07 Oct 2020 17:19:35 GMT</pubDate></item><item><title><![CDATA[Reply to Regex alternation in both FIND & REPLACE strings on Wed, 07 Oct 2020 08:16:06 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/58320">Regex alternation in both FIND &amp; REPLACE strings</a>:</p>
<blockquote>
<p dir="auto">Look again at the <code>(</code> at the start. You have 2 before you get to the first alternate Outtake. It is inside the 2nd set so it is the ?2 in the replacement. All the others are also 1 out from what you thought.</p>
</blockquote>
<p dir="auto">Ha! Right you are! Which leads me to another realization (read on…)</p>
<blockquote>
<p dir="auto">Alternatively change each ?# in the Replace With code adding 1 to the current number.</p>
</blockquote>
<p dir="auto">I’m sure that would work as well, but I think what I really should have done to begin with was make the outer <code>()</code> a non-capture group, so my find string should have started <code>" (?:(\(Outtake\))|(\(Alternate Version\))|</code>… which I’ve now verified does the job.</p>
<p dir="auto">Some background: My first attempt at this was made without the outer <code>()</code>, but I found I had to do something different because my initial results ended up looking like this:</p>
<pre><code>1. “Track 1” — 	3:24
2. “Track 2"  [alt]” — 	3:30
3. “Track 3"  [drone mix]” — 	2:51
4. “Track 4"  [alt]” — 	4:08
5. “Track 5"  [rehearsal]” — 	4:34
6. “Track 6"  [alt]” — 	3:34
7. “Track 7"  [string mix]” — 	4:29
8. “Track 8"  [rehearsal]” — 	1:40
9. “Track 9"  [alt]” — 	4:50
10. “Track 10"  [rehearsal]” — 	2:52
11. “Track 11"  [piano mix]” — 	6:09
12. “Track 12"  [instrumental]” — 5:17
</code></pre>
<p dir="auto">…in which all the characters outside of the alternation sequence in my <strong>FIND</strong> string (<code>" </code> at the beginning, <code>\t</code> at the end) apparently got ignored, except in the first line where the <code>"</code> actually did get replaced (and I’m not clear on why that happened, but maybe one of you regex masters is?). So I tried adding the outer <code>()</code>, but neglected to make it non-capturing.</p>
<p dir="auto">Thanks much for the advice and helpful references, Terry.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58324</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58324</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Wed, 07 Oct 2020 08:16:06 GMT</pubDate></item><item><title><![CDATA[Reply to Regex alternation in both FIND & REPLACE strings on Wed, 07 Oct 2020 05:50:31 GMT]]></title><description><![CDATA[<p dir="auto">The best description I can currently find is here<br />
<a href="http://rexegg.com/regex-capture.html#groupnumbers" rel="nofollow ugc">http://rexegg.com/regex-capture.html#groupnumbers</a><br />
Basically you count left brackets from left to right as 1,2,3,… . There are however exceptions to that rule including branch resets (Very similar to the type of coding you used) so you do need to know how to count these correctly.</p>
<p dir="auto">I think you assumed ?1 referred to the first alternate selection, whereas that will always be the selection within the first set of brackets. So if an alternate code exists at the end of a complex regex quite possibly the first alternate group might be something like ?8.</p>
<p dir="auto">The site I linked above I find gives a lot of great information but be aware there are many regular expression engines out there and this site does have some information which does NOT fit exactly to Notepad++ needs.</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58321</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58321</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Wed, 07 Oct 2020 05:50:31 GMT</pubDate></item><item><title><![CDATA[Reply to Regex alternation in both FIND & REPLACE strings on Wed, 07 Oct 2020 05:20:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/m-andre-z-eckenrode" aria-label="Profile: M-Andre-Z-Eckenrode">@<bdi>M-Andre-Z-Eckenrode</bdi></a> said in <a href="/post/58318">Regex alternation in both FIND &amp; REPLACE strings</a>:</p>
<blockquote>
<p dir="auto">Is there a trick I’m missing?</p>
</blockquote>
<p dir="auto">No trick. Look again at the <code>(</code> at the start. You have 2 before you get to the first alternate Outtake. It is inside the 2nd set so it is the ?2 in the replacement. All the others are also 1 out from what you thought.</p>
<p dir="auto">If you put the find what regex into Notepad++ as if it is just text then by moving through the code Notepad++ will show you the pair (highlight in red) to each ( or ) to help you figure out where you need to prune an unwanted set. Alternatively change each ?# in the Replace With code adding 1 to the current number. That might get you closer to what you want.</p>
<p dir="auto">I’m not on a PC currently to test but think that should do it.</p>
<p dir="auto">Terry</p>
<p dir="auto">Terry</p>
]]></description><link>https://community.notepad-plus-plus.org/post/58320</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58320</guid><dc:creator><![CDATA[Terry R]]></dc:creator><pubDate>Wed, 07 Oct 2020 05:20:52 GMT</pubDate></item><item><title><![CDATA[Reply to Regex alternation in both FIND & REPLACE strings on Wed, 07 Oct 2020 04:10:37 GMT]]></title><description><![CDATA[<p dir="auto">Correction — last line of actual result should have read:</p>
<pre><code>12. “Track 12” — 5:17
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/58319</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/58319</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Wed, 07 Oct 2020 04:10:37 GMT</pubDate></item></channel></rss>