<?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[PythonScript regex error, but not as NPP regex]]></title><description><![CDATA[<p dir="auto">I use PythonScript, mostly for extended sequences of regular expressions find &amp; replace operations. I typically test my regex code directly in Notepad++ via the built-in Find/Replace dialog before putting it into a script. Both my files being operated on and my scripts are nearly always ANSI/Windows-1252, but I want my scripts to be able to work on unicode text as well. A new script I’m working on includes this problematic line of code:</p>
<pre><code>editor.rereplace(r'(\)) (&lsqb;&lsqb;:alpha:&rsqb;&rsqb;+) (&lsqb;&lsqb;:alpha:&rsqb;&rsqb;+ — )', ur'\1\r\n\t\u\2 \u\3')
</code></pre>
<p dir="auto">That line results in the following error message in PythonScript’s console:</p>
<pre><code>File "C:\Users\MAZE\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\McCartney-Project.py", line 25
    editor.rereplace(r'(\)) (&lsqb;&lsqb;:alpha:&rsqb;&rsqb;+) (&lsqb;&lsqb;:alpha:&rsqb;&rsqb;+ x97 )', ur'\1\r\n\t\u\2 \u\3')
SyntaxError: (unicode error) 'rawunicodeescape' codec can't decode bytes in position 8-9: truncated \uXXXX
</code></pre>
<p dir="auto">However, that actual regex works directly in NPP. It looks offhand like my m-dash (<code>—</code>) is the root of the problem, as it’s replaced by <code>x97</code> in the error message, but I use an ANSI m-dash in several other regex operations coming before that line in the same script, and PythonScript doesn’t complain about any of them, and DOES process them as expected (after I’ve commented out the offending line). Anybody know why that particular line is a stumbling block?</p>
<p dir="auto">Notepad++ v8.8.5   (32-bit)<br />
Build time: Aug 14 2025 - 00:17:53<br />
Scintilla/Lexilla included: 5.5.7/5.4.5<br />
Boost Regex included: 1_85<br />
Path: C:\Program Files (x86)\Notepad++\notepad++.exe<br />
Command Line: “C:\Program Files\ArdfryImaging\PNGOUTWin\PNGOUTWin Reg Codes.txt”<br />
Admin mode: OFF<br />
Local Conf mode: OFF<br />
Cloud Config: OFF<br />
Periodic Backup: ON<br />
Placeholders: OFF<br />
Scintilla Rendering Mode: SC_TECHNOLOGY_DIRECTWRITE (1)<br />
Multi-instance Mode: monoInst<br />
asNotepad: OFF<br />
File Status Auto-Detection: cdEnabledNew (for current file/tab only)<br />
Dark Mode: OFF<br />
Display Info:<br />
primary monitor: 1920x1080, scaling 100%<br />
visible monitors count: 1<br />
installed Display Class adapters:<br />
0000: Description - Intel® HD Graphics 620<br />
0000: DriverVersion - 31.0.101.2111<br />
0001: Description - NVIDIA GeForce 940MX<br />
0001: DriverVersion - 30.0.15.1169<br />
OS Name: Windows 10 Enterprise (64-bit)<br />
OS Version: 22H2<br />
OS Build: 19045.6216<br />
Current ANSI codepage: 1252<br />
Plugins:<br />
BetterMultiSelection (1.5)<br />
ColumnsPlusPlus (1.2)<br />
ColumnTools (1.4.5.1)<br />
ComparePlus (1.2)<br />
DSpellCheck (1.5)<br />
ExtSettings (1.3.1)<br />
HTMLTag_unicode (1.5.4)<br />
mimeTools (3.1)<br />
MultiClipboard (2.1)<br />
MultiReplace (4.3.2.28)<br />
NppCalc (1.5)<br />
NppConverter (4.6)<br />
NppExport (0.4)<br />
NPPJSONViewer (2.1.1)<br />
NppTextFX (1.4.1)<br />
NppXmlTreeviewPlugin (2)<br />
PreviewHTML (1.3.3.2)<br />
PythonScript (2.1)<br />
RegexTrainer (1.2)<br />
SessionMgr (1.4.4)</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/27117/pythonscript-regex-error-but-not-as-npp-regex</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Jul 2026 17:03:52 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/27117.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Sep 2025 15:44:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PythonScript regex error, but not as NPP regex on Tue, 02 Sep 2025 19:04:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a></p>
<p dir="auto">Thanks much. My bad for even bringing it up, actually, since I already had <a href="https://community.notepad-plus-plus.org/post/69338">back in 2021</a> and was advised about the lambda workaround at that time. Forgot about that.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/103130</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/103130</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Tue, 02 Sep 2025 19:04:33 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript regex error, but not as NPP regex on Tue, 02 Sep 2025 16:34: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">Unfortunately, this is still an open <a href="https://github.com/bruderstein/PythonScript/issues/199" rel="nofollow ugc">issue</a>,</p>
<p dir="auto">In this specific case you can use something like this</p>
<pre><code class="language-python">editor.rereplace(r'(\)) (&lsqb;&lsqb;:alpha:&rsqb;&rsqb;+) (&lsqb;&lsqb;:alpha:&rsqb;&rsqb;+ — )', lambda m: f'{m.group(1)}\r\n\t{m.group(2).title()} {m.group(3).title()}')
</code></pre>
<p dir="auto">EDIT: oopss - just realized you are still using python 2</p>
<pre><code class="language-python">editor.rereplace(r'(\)) (&lsqb;&lsqb;:alpha:&rsqb;&rsqb;+) (&lsqb;&lsqb;:alpha:&rsqb;&rsqb;+ — )', lambda m: '{}\r\n\t{} {}'.format(m.group(1), m.group(2).title(), m.group(3).title()))
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/103127</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/103127</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 02 Sep 2025 16:34:47 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript regex error, but not as NPP regex on Tue, 02 Sep 2025 16:02:26 GMT]]></title><description><![CDATA[<p dir="auto">Actually, I’m now thinking that my use of <code>\u</code> is the problem. I’m looking for it to cause the next character to be output in UPPER CASE, but looks like Python is expecting four hexadecimal digits to specify a Unicode code point.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/103126</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/103126</guid><dc:creator><![CDATA[M Andre Z Eckenrode]]></dc:creator><pubDate>Tue, 02 Sep 2025 16:02:26 GMT</pubDate></item></channel></rss>