Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re module not matching [\s\S] and equivalents #8525

Closed
michalpokusa opened this issue Oct 26, 2023 · 5 comments
Closed

re module not matching [\s\S] and equivalents #8525

michalpokusa opened this issue Oct 26, 2023 · 5 comments
Labels
Milestone

Comments

@michalpokusa
Copy link

CircuitPython version

Adafruit CircuitPython 8.2.4 on 2023-08-22; Adafruit Feather ESP32-S2 TFT with ESP32S2

Code/REPL

>>> import re
>>> re.search(r">\S*?<", ">test<") is None
False
>>> re.search(r">\s*?<", "> <") is None
False
>>> re.search(r">[\s\S]*?<", "> test <") is None
True
>>> re.compile(">.*?<", 16).search("> test <") is None
False

Behavior

When searching for \S aka any non-whitespace character, re module finds a match.
Similarly, when searching for \s aka any whitespace character, re module also finds a match.

But, when combining them together, creating a popular any character re module is unable to match.

This pattern is correct, and in theory should be possible to use in CircuitPython, as all the components (\s, \S, sets [], non-greedy *?) are supported.
image

Similar issue hapens when using \d and \D, \w and \W.

Using .compile() with re.DOTALL which is a literal 16, and with changed patterns ([\s\S] to .) seems to make it possible to match such strings, but still, the issue is present, it is just going around it.

Description

No response

Additional information

Possibly related, but maybe the cause is completely different: #6860

@michalpokusa michalpokusa changed the title re module not matching [\s\S] and equivalents re module not matching [\s\S] and equivalents Oct 26, 2023
@dhalbert
Copy link
Collaborator

Could you test this on a 9.0.0 build to see if the updates from MicroPython fixed it? Thanks.

@michalpokusa
Copy link
Author

Could you test this on a 9.0.0 build to see if the updates from MicroPython fixed it? Thanks.

Sure thing. I will test and come back with results.

@michalpokusa
Copy link
Author

Well, turns out it does in fact seem to fix the issue. I probably should have tested it myself before posting. Sorry for that.
image

@dhalbert
Copy link
Collaborator

No problem - this is good. We'll want to decide whether to backport the fix to 8.2.x or simply leave your workaround in until 8.x.x has been supplanted by 9.x.x.

@dhalbert dhalbert added this to the 8.2.x milestone Oct 28, 2023
@dhalbert
Copy link
Collaborator

dhalbert commented Nov 7, 2023

I will close this, since it's fixed in 9.0.0. We could backport the fix to 8.2.x but having the workaround in the library is good for anyone running a slightly older version, so no need to backport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants