@@ -440,6 +440,36 @@ def __ne__(self, other) -> bool:
440440def matches_regex (regex ):
441441 return RegexMatcher (regex , re .compile (regex ))
442442
443+ class MultiRegexMatcher (ValidatorBase ):
444+ def __init__ (self , regex_list : list [str ], compiled_list : list [re .Pattern ]) -> None :
445+ self .regex_list = regex_list
446+ self ._compiled_list = compiled_list
447+
448+ def __call__ (self , value : str ) -> bool :
449+ str_value = str (value )
450+ for compiled_pattern in self ._compiled_list :
451+ if compiled_pattern .match (str_value ) is not None :
452+ return True
453+ return False
454+
455+ def __deepcopy__ (self , dummy_memo ):
456+ return type (self )(self .regex_list [:], self ._compiled_list [:])
457+
458+ def __str__ (self ):
459+ patterns_str = " | " .join (self .regex_list )
460+ return "'x' matches any of: /%s/" % patterns_str
461+
462+ def __eq__ (self , other ):
463+ return isinstance (other , type (self )) and self .regex_list == other .regex_list
464+
465+ def __ne__ (self , other ) -> bool :
466+ return not self == other
467+
468+ @register
469+ def matches_any_regex (regex_list : list [str ]):
470+ compiled_list = [re .compile (regex ) for regex in regex_list ]
471+ return MultiRegexMatcher (regex_list , compiled_list )
472+
443473
444474class WithinPercent (RangeValidatorBase ):
445475 """Validates that a number is within percent of a value."""
0 commit comments