To implement custom regex logic, subclass MelusineRegex and implement the required properties.
positive: A str or Dict[str, str] defining the patterns you want to match. If using a dictionary, keys are identifiers and values are the regex patterns.match_list: A List[str] of example strings that must match your regex. This is used for automated testing during instantiation.no_match_list: A List[str] of example strings that must not match your regex. This is also used for automated testing during instantiation.negative (optional): A str or Dict[str, str] defining patterns that, if matched, will cancel out any positive matches.neutral (optional): A str or Dict[str, str] defining patterns that, if matched, will "blur" the text, preventing subsequent positive matches from triggering on that specific content.
from melusine.base import MelusineRegex
from typing import Union, Dict, List
class AnnoyingEmailsRegex(MelusineRegex):
@property
def positive(self) -> Union[str, Dict[str, str]]:
return dict(
VOLDY_BEING_VOLDY="Avada Kedavra",
GANDALF_BEING_GANDALF="You shall not pass",
)
@property
def match_list(self) -> List[str]:
return [
"Avada Kedavra is a spell used by Lord Voldemort",
"And then, you know me, I was not gonna let it pass so I told them : You shall not pass and obviously everyone clapped",
]
@property
def no_match_list(self) -> List[str]:
return ["Abracadabra, here I am", "I told them not to pass"]