-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Open
Labels
Description
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.