def pseudonymize(self, content): if not content: return content content_modified = '' start = 0 for mo in re.finditer("\[\*\*[^\[]*\*\*\]", content): replacement = self.mapper.get_mapping(mo.group(0)) content_modified += content[start: mo.start()] content_modified += replacement start = mo.end() if start < len(content): content_modified += content[start: len(content)] return content_modified