Skip to content

ure returns different results than using re (Regular expression) #11724

@maxi07

Description

@maxi07

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugextmodRelates to extmod/ directory in source

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions