<?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[Python Script Regex replace with uppercase]]></title><description><![CDATA[<p dir="auto">Hello again, all. In the midst of constructing a new Python Script regex replacement script, I’ve hit a snag using my usual methods, but found a workaround which has taken care of my use cases so far, but wonder if anybody here knows of a more universal fix. Debug info:</p>
<p dir="auto">Notepad++ v8.1.3   (32-bit)<br />
Build time : Aug 10 2021 - 00:32:53<br />
Path : C:\Program Files (x86)\Notepad++\Notepad++.exe<br />
Command Line : -multiInst -nosession<br />
Admin mode : OFF<br />
Local Conf mode : OFF<br />
Cloud Config : OFF<br />
OS Name : Windows 10 Enterprise (64-bit)<br />
OS Version : 2004<br />
OS Build : 19041.1165<br />
Current ANSI codepage : 1252<br />
Plugins : ComparePlugin.dll DSpellCheck.dll ElasticTabstops.dll ExtSettings.dll mathpad.dll mimeTools.dll MultiClipboard.dll NppCalc.dll NppConverter.dll NppExport.dll NPPJSONViewer.dll NppQrCode32.dll NppSaveAsAdmin.dll NppTextFX.dll NppXmlTreeviewPlugin.dll PythonScript.dll SessionMgr.dll</p>
<p dir="auto">It should be noted (again; I have pointed this out in previous topic “<a href="https://community.notepad-plus-plus.org/post/54624">Intricacies of Regex Replace via Python Script</a>”) that I deal almost exclusively with ANSI text, Windows-1252 encoded text files, but do process the odd Unicode text file now and then, and prefer my scripts to be able to handle both if possible.</p>
<p dir="auto">My Python Script code to search for and capture lowercase characters at the start of any line and replace with uppercase:</p>
<pre><code>editor.rereplace(r'(?-i)^([a-z])', ur'\U\1')
</code></pre>
<p dir="auto">This has resulted in error message: “SyntaxError: (unicode error) ‘rawunicodeescape’ codec can’t decode bytes in position 0-1: truncated \uXXXX”</p>
<p dir="auto">I seem to have identified the source of the problem as being <code>ur'\U\1'</code>, apparently because Python is expecting a sequence of digits following the <code>\U</code> in order to represent some Unicode character, whereas I only want an uppercase character to replace a lowercase character. If I change the code to <code>r'\U\1'</code>, it works in my ANSI text test cases — but it was previously suggested to me to use <code>ur''</code> in my replacement code in order to have it work with both ANSI and Unicode text. Do I have any other options?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/21744/python-script-regex-replace-with-uppercase</link><generator>RSS for Node</generator><lastBuildDate>Sun, 11 Oct 2026 03:01:51 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/21744.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 28 Aug 2021 00:57:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 19:29:09 GMT]]></title><description><![CDATA[<p dir="auto">Sorry for the late and already too late reply, but I usually stay away from the computer on weekends.</p>
<p dir="auto">I assume that Python does its string processing before the boost::regex function gets a chance to interpret the string, but I’ve never really looked into it. The lambda or explicit function solution seem to be the way to solve this problem.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69411</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69411</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 31 Aug 2021 19:29:09 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 19:23:37 GMT]]></title><description><![CDATA[<p dir="auto">It might have been instructive for the PythonScript docs to have shown the <code>add_1</code> example as a lambda, e.g.:</p>
<p dir="auto"><code>editor.rereplace('X([0-9]+)', lambda m: 'Y' + str(int(m.group(1)) + 1))</code></p>
<hr />
<p dir="auto">For those without easy access to the PythonScript docs, here’s what they DO show:</p>
<pre><code class="language-z">def add_1(m):
    return 'Y' + str(int(m.group(1)) + 1)

# replace X followed by numbers by an incremented number
# e.g.   X56 X39 X999
#          becomes
#        Y57 Y40 Y1000

editor.rereplace('X([0-9]+)', add_1);
</code></pre>
<p dir="auto">And, No, I’ve no idea what’s up with the trailing semicolon on the last line of that example.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69410</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69410</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 31 Aug 2021 19:23:37 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 19:17:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/69408">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto">you don’t even need to know about lambdas for the problem at hand: Really, you just need to learn, as the PythonScript documentation showed, that <code>rereplace</code> allows either a replacement expression <em>or</em> a function that it will call on the matching text.</p>
</blockquote>
<p dir="auto">Noted, and thank you for the more detailed explanation. Although I can’t think of any immediate use for a lambda function other than your helpful suggestion for <code>rereplace</code> just now, it’s certainly possible on will come to me in the future, so I’m happy to learn more about it than I absolutely have to for my present needs — even though a refresh and more thorough study of it will surely be necessary when the time comes.</p>
<p dir="auto">Thanks again to you and <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> for your help.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69409</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69409</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Tue, 31 Aug 2021 19:17:01 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 18:32:27 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/69405">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/69404">Python Script Regex replace with uppercase</a>:<br />
I see only a passing mention in the <a href="http://npppythonscript.sourceforge.net/docs/latest/scintilla.html?highlight=lambda" rel="nofollow ugc">Python Script doc page for ‘Editor Object’</a>,</p>
</blockquote>
<p dir="auto">There’s only a passing mention because, as <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> explained, it’s a standard feature in Python (and elsewhere).</p>
<p dir="auto">And you don’t even need to know about lambdas for the problem at hand: Really, you just need to learn, as the PythonScript documentation showed, that <code>rereplace</code> allows either a replacement expression <em>or</em> a function that it will call on the matching text.  A lambda function or a normally-defined function will both work equally well (like the infamous <code>add_1</code> in the PS docs).  The function accesses the text of the match through the <code>m.group(#)</code> where # aligns with the capture groups in your regular expression match expression.  The function should return the text that you want to replace the <em>entire match</em> with (in your case, the function-based equivalent of <code>\U\1</code>).  So when <code>rereplace</code> finds a match, it will send that match as <code>m</code> to the function, and then the function returns the replacement value; then <code>rereplace</code> moves on to the next match and calls the function again, until no more matches are found.  (To make it abundantly clear, your function does <em>not</em> need to loop through the matches; that is handled by the <code>rereplace</code>; your function just needs to transform one match <code>m</code> into some text to return to be used as the replacement.)</p>
<p dir="auto">The call <code>editor.rereplace(r'(?-i)^([a-z])', lambda m: m.group(1).upper())</code> is exactly equivalent to the longer script</p>
<pre><code>def do_capitalize(m):
    return m.group(1).upper()

editor.rereplace(r'(?-i)^([a-z])', do_capitalize)
</code></pre>
<p dir="auto">… but it fits nicely in a one-liner.  If your replacement function required more than one line (if you wanted to build a more complicated string through various calculations), then you’d have to use the defined-function variant instead of a lambda function.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69408</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69408</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 31 Aug 2021 18:32:27 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 18:20:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/69406">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto">Read more about them by “googling” for “lambda functions in Python”.</p>
</blockquote>
<p dir="auto">Ok, thanks much.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69407</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69407</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Tue, 31 Aug 2021 18:20:30 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 18:10:43 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/69405">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto">Where can I read more about lambda?</p>
</blockquote>
<p dir="auto">lambda functions are part of Python, not specific to Notepad++'s PythonScript plugin.</p>
<p dir="auto">Read more about them by “googling” for “lambda functions in Python”.</p>
<p dir="auto">lambda functions are available in other programming languages as well, so it is not even something specific to Python (but that’s the context here, so…).</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69406</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69406</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 31 Aug 2021 18:10:43 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 18:07:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/69404">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto">Instead of doing the lowercase through a regex replacement in the <code>rereplace</code>, what about a lambda function?</p>
</blockquote>
<p dir="auto">I’ve never even heard of that before, but it sounds like a promising work-around unless and until an actual fix for <code>rereplace</code> is in place, if possible. Where can I read more about lambda? I see only a passing mention in the <a href="http://npppythonscript.sourceforge.net/docs/latest/scintilla.html?highlight=lambda" rel="nofollow ugc">Python Script doc page for ‘Editor Object’</a>, and though typing ‘lambda’ in the search box for the <a href="https://npp-user-manual.org/" rel="nofollow ugc">online NPP user manual</a> makes it appear that it can be found in numerous sections including <a href="https://npp-user-manual.org/docs/searching/" rel="nofollow ugc">‘Searching’</a>, I’m unable to locate any specific instance of it there using my browser’s ‘Find’ facility.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69405</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69405</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Tue, 31 Aug 2021 18:07:54 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 15:56:12 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> ,</p>
<p dir="auto">Instead of doing the lowercase through a regex replacement in the <code>rereplace</code>, what about a lambda function? <code>editor.rereplace(r'(?-i)^([A-Z])', lambda m: m.group(1).lower())</code> worked in all three of the test file conditions I listed in my previous post.</p>
<p dir="auto">And the opposite, which your original question asked for, <code>editor.rereplace(r'(?-i)^([a-z])', lambda m: m.group(1).upper())</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/69404</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69404</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 31 Aug 2021 15:56:12 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 15:32:47 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> ,</p>
<p dir="auto">Weird.</p>
<p dir="auto">I just tried a comparison:</p>
<pre><code>Zz
Yy
XxXx

C_
À
Á
Â
Ã
Ä
Å
</code></pre>
<ol>
<li>
<p dir="auto">File that is Encoding &gt; ANSI: <img src="/assets/uploads/files/1630423752516-f03b0786-610d-4cf8-97b7-f8ef8fa9f85d-image.png" alt="f03b0786-610d-4cf8-97b7-f8ef8fa9f85d-image.png" class=" img-fluid img-markdown" /> =&gt; <code>editor.rereplace(r'(?-i)^([A-Z])', ur'\L\1')</code> =&gt;  <img src="/assets/uploads/files/1630423774183-1ef54b3e-41fc-4d50-823e-c6c825cc1a7e-image.png" alt="1ef54b3e-41fc-4d50-823e-c6c825cc1a7e-image.png" class=" img-fluid img-markdown" /></p>
</li>
<li>
<p dir="auto">File that is Encoding &gt; Charset &gt; Western &gt; Windows-1252: same file, same rereplace line, no characters go lowercase</p>
</li>
<li>
<p dir="auto">File that is Encoding &gt; UTF-8: same file, same rereplace line, no characters go lowercase</p>
</li>
</ol>
<p dir="auto">So ANSI works differently than a forced charset or forced UTF-8.</p>
<p dir="auto">-–<br />
<strong>addendum</strong>:</p>
<pre><code>Notepad++ v8.1.4   (64-bit)
Build time : Aug 21 2021 - 13:04:59
Path : C:\usr\local\apps\notepad++\notepad++.exe
Command Line : 
Admin mode : OFF
Local Conf mode : ON
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit) 
OS Version : 2009
OS Build : 19042.1165
Current ANSI codepage : 1252
Plugins : AutoSave.dll ComparePlugin.dll ExtSettings.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppConsole.dll NppConverter.dll NppEditorConfig.dll NppExec.dll NppExport.dll NppFTP.dll NppUISpy.dll PreviewHTML.dll PythonScript.dll QuickText.dll TagLEET.dll XMLTools.dll 
</code></pre>
<p dir="auto"><code>Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)]</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/69403</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69403</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 31 Aug 2021 15:32:47 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 15:20:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/69400">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto"><code>editor.rereplace(r'(?-i)([A-Z])', ur'\L\1')</code></p>
</blockquote>
<p dir="auto">Interesting… I used a nearly identical line of code here, and it works for me:</p>
<p dir="auto"><code>editor.rereplace(r'(?-i)^([A-Z])', ur'\L\1')</code></p>
<p dir="auto">Note that my script file is itself ANSI/Windows-1252, and therefore begins with the following line:</p>
<p dir="auto"><code># encoding: Windows-1252</code></p>
<p dir="auto">I’m guessing yours is Unicode, and maybe that’s the interfering factor?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69402</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69402</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Tue, 31 Aug 2021 15:20:18 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 15:01:02 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/69395">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto">since \L and l DO work for me via Python Script.</p>
</blockquote>
<p dir="auto">With PS 1.5.4, I tried this and it didn’t replace anything, so <code>\L</code> doesn’t appear to work for me:</p>
<p dir="auto"><code>editor.rereplace(r'(?-i)([A-Z])', ur'\L\1')</code></p>
<p dir="auto">And yes, I had some uppercase characters in my doc; I also tested by using <code>@</code> as the replace string, just to verify the replacement in general was working – it was.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69400</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69400</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 31 Aug 2021 15:01:02 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 14:04:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/69394">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto">Perhaps <a href="https://github.com/bruderstein/PythonScript/issues/199" rel="nofollow ugc">THIS</a> is a barrier to it working regardless of what’s been discussed so far?</p>
</blockquote>
<p dir="auto">Good catch and point, though I think there must be something more at play here, since <code>\L</code> and <code>l</code> <em>DO</em> work for me via Python Script.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69395</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69395</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Tue, 31 Aug 2021 14:04:22 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 13:36:09 GMT]]></title><description><![CDATA[<p dir="auto">Perhaps <a href="https://github.com/bruderstein/PythonScript/issues/199" rel="nofollow ugc">THIS</a> is a barrier to it working regardless of what’s been discussed so far?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69394</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69394</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Tue, 31 Aug 2021 13:36:09 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Tue, 31 Aug 2021 12:53:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> said in <a href="/post/69370">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto">You might want to experiment with <code>ur'\\U\1</code> to see if double-escaping the U will allow the <code>\U</code> to pass through to the boost::regex engine.</p>
</blockquote>
<p dir="auto">Thanks for the reply and suggestions, Peter. Unfortunately, using <code>\\U\1</code> results in “\U” getting inserted into my text. I’ll hold out hope for some wisdom from <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> or anyone else more knowledgeable and experienced than myself.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69392</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69392</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Tue, 31 Aug 2021 12:53:21 GMT</pubDate></item><item><title><![CDATA[Reply to Python Script Regex replace with uppercase on Sun, 29 Aug 2021 18:02:18 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/69338">Python Script Regex replace with uppercase</a>:</p>
<blockquote>
<p dir="auto">Do I have any other options?</p>
</blockquote>
<p dir="auto">Probably.  Unfortunately, I am not enough of a Python expert, and I’m not good with the intracies of its “string” vs “Unicode  string” handling.  I was hoping <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> would have chimed in as the regular who seems to best understand the intricacies of Python, but he hasn’t logged in yet this weekend.  This @-mention should trigger a notification, so the next time he does log in, it will flag this post for him.</p>
<p dir="auto">However, I am not sure if PythonScript 1.5.4, which uses Python 2.7.18, will have the <code>\U</code> = upper-case substitution expression – I don’t see it in the <a href="https://docs.python.org/2.7/library/re.html" rel="nofollow ugc">https://docs.python.org/2.7/library/re.html</a> documentation.  The Python 3 re doc (<a href="https://docs.python.org/3/library/re.html" rel="nofollow ugc">https://docs.python.org/3/library/re.html</a>) <em>does</em> list <code>\U</code>, but in the context of embedding a unicode character.</p>
<p dir="auto">But the previous post you linked seems to indicate <code>editor.rereplace</code> is using the boost regex engine like Notepad++ uses, in which case it should know the <code>\U</code> notation – hence why it works for your ASCII strings with a raw-only string for the replacement</p>
<p dir="auto">So my next guess is that by combining raw and unicode string indicators, it enables the <code>\u</code> notation (which per <a href="https://docs.python.org/2.7/howto/unicode.html#the-unicode-type" rel="nofollow ugc">https://docs.python.org/2.7/howto/unicode.html#the-unicode-type</a> is available in 2.7), and thus Python turns that into a unicode-escape <em>before</em> it gets to the boost engine.  You might want to experiment with <code>ur'\\U\1</code> to see if double-escaping the U will allow the <code>\U</code> to pass through to the boost::regex engine.  I don’t know.</p>
<p dir="auto">I don’t know if anything I said will help.  Mostly, I replied to let you know “we’re not ignoring you”, and to @-mention <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a>.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/69370</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/69370</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Sun, 29 Aug 2021 18:02:18 GMT</pubDate></item></channel></rss>