Skip to content

Rule Class Reference

Rule

Defines the allowed structure of a single Field.

A Rule is centered on a regular expression pattern which is used to validate field values.

Parameters:

  • pattern (str) –

    Regular expression pattern (string).

  • examples (list[str], default: list[str]() ) –

    Optional list of example strings that should match the pattern.

Attributes

examples

examples: list[str] = dataclass_field(default_factory=list[str])

name

name: str = dataclass_field(default='', init=False)

pattern

pattern: str

Methods:

get_mismatch_message

get_mismatch_message(string: str) -> str

Return a human-readable message for a mismatch, including examples when available.

match

match(string: str, raise_exception: bool = False) -> bool

Return whether the provided string matches this Rule.

Parameters:

  • string (str) –

    The string to match against the compiled pattern.

Returns:

  • bool ( bool ) –

    True if the pattern matches the entire string, False otherwise.