def METHOD_NAME(self, text: str, rng: Random) -> str:
    """Substitute the source dialect in text with the target dialect with probability self.prob."""
    # Substitution function
    def sub_func(m: re.Match):
        match_str = m.group(0)  # The full match (e.g. " With ", " With,", " With.")
        word = m.group(1)  # Captured group (e.g. "With")
        if rng.uniform(0, 1) < self.prob:
            synonyms = self.mapping_dict[word.lower()]
            synonym = rng.choice(synonyms)  # Synonym (e.g. "wit")
            synonym = match_case(word, synonym)  # Synoynm with matching case (e.g. "Wit")
            match_str = match_str.replace(
                word, synonym
            )  # Synonym placed in the matching group (e.g. " Wit ", " Wit,", " Wit.")
        return match_str
    # Execute the RegEx
    return re.sub(self.pattern, sub_func, text, flags=re.IGNORECASE)