0xf0f/reaper-api

Regular expression results in `SyntaxWarning` in recent versions of Python 3.x

rcook opened this issue · 1 comments

See https://github.com/0xf0f/reaper-api/blob/master/reaper_python.py#L19C5-L19C58.

For example, using Python 3.12.1:

$ python3
Python 3.12.1 (main, Jan  8 2024, 06:38:22) [Clang 16.0.3 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> m=re.match('^\((\w+\*|HWND)\)0x([0-9A-F]+)$', str("FOO"))
<stdin>:1: SyntaxWarning: invalid escape sequence '\('

This results in warnings output to the ReaScript error dialog when other errors occur.

I think the fix would be to escape the backslash characters:

>>> m=re.match('^\\((\\w+\\*|HWND)\\)0x([0-9A-F]+)$', str("FOO"))

I have not been able to verify that this regular expression behaves exactly the same or not.

I have confirmed that '^\\((\\w+\\*|HWND)\\)0x([0-9A-F]+)$' represents an identical regular expression:

import re
re0 = re.compile('^\((\w+\*|HWND)\)0x([0-9A-F]+)$')
re1 = re.compile('^\\((\\w+\\*|HWND)\\)0x([0-9A-F]+)$')
assert re0 == re1