QUERY · ISSUE
search() on a compiled regular expression ignores the "pos" argument
extmod
With MicroPython v1.16 (on 2021-06-18; Raspberry Pi Pico with RP2040), I observe the following unexpected output from .search() with a pos argument on a compiled regular expression:
>>> import re
>>> RE = re.compile("a")
>>> print(RE.search("ab", 1) is None)
False # Should be True
Same result on MicroPython v1.12-1 on 2020-02-09; linux version. Contrast with Python 3.8.10:
>>> import re
>>> RE = re.compile("a")
>>> print(RE.search("ab", 1) is None)
True
It seems that the pos parameter is ignored in MicroPython?
>>> print(RE.search("aa", 1).span())
(0, 1) # Should be (1, 2)
CANDIDATE · ISSUE
ure returns different results than using re (Regular expression)
bugextmod
Hello,
this is my function to validate for HEX colors.
try:
import ure as re
except ModuleNotFoundError:
import re
def is_valid_color(color: str) -> bool:
"""Validate the color format using a regular expression"""
try:
color_pattern = r'^#[0-9a-fA-F]{6}$'
return re.match(color_pattern, color) is not None
except Exception as ex:
print("Failed validating color:", ex)
return False
print(is_valid_color("#00ff33"))
When this code is executed using micropython 1.20.0, the function returns False. When run with Python 3.11, the function returns True. I was expecting a True result, as the regular expression does match with the search string. This can be verified using Regex101, which does find a match.