Skip to content

Regex match

RegexMatch

Bases: BaseValidator

Validates that a value matches a regular expression.

Parameters:

Name Type Description Default
regex

A regular expression pattern.

required
match_type

Match type to check input value for a regex search or full-match option.

required
Source code in dynamiq/nodes/validators/regex_match.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class RegexMatch(BaseValidator):
    """
    Validates that a value matches a regular expression.

    Args:
        regex: A regular expression pattern.
        match_type: Match type to check input value for a regex search or full-match option.
    """

    regex: str
    match_type: MatchType | None = MatchType.FULL_MATCH

    def validate(self, content: str):
        """
        Validates if the provided value matches the given regular expression pattern.

        Args:
            content (str): The value to validate.

        Raises:
            ValueError: If the provided value does not match the given pattern.
        """
        compiled_pattern = re.compile(self.regex)
        match_method = getattr(compiled_pattern, self.match_type)
        if not match_method(content):
            raise ValueError(
                f"Value does not match the valid pattern. Value: '{content}'. Pattern: '{self.regex}'",
            )

validate(content)

Validates if the provided value matches the given regular expression pattern.

Parameters:

Name Type Description Default
content str

The value to validate.

required

Raises:

Type Description
ValueError

If the provided value does not match the given pattern.

Source code in dynamiq/nodes/validators/regex_match.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def validate(self, content: str):
    """
    Validates if the provided value matches the given regular expression pattern.

    Args:
        content (str): The value to validate.

    Raises:
        ValueError: If the provided value does not match the given pattern.
    """
    compiled_pattern = re.compile(self.regex)
    match_method = getattr(compiled_pattern, self.match_type)
    if not match_method(content):
        raise ValueError(
            f"Value does not match the valid pattern. Value: '{content}'. Pattern: '{self.regex}'",
        )