19 lines
705 B
Python
19 lines
705 B
Python
import re
|
|
from copy import deepcopy
|
|
|
|
class FindAndReplace:
|
|
def __init__(self, map: dict[str, list[str]], reqire_full_match: bool = False):
|
|
self.map = map
|
|
self.require_full_match = reqire_full_match
|
|
|
|
def execute_on_cell(self, entry) -> str:
|
|
res = deepcopy(entry.value)
|
|
|
|
for correct_name, bad_names in self.map.items():
|
|
for bad_name in bad_names:
|
|
if self.require_full_match and bad_name == res:
|
|
# Todo remove random leading/trailing spaces before if
|
|
res = correct_name
|
|
elif not self.require_full_match:
|
|
res = res.replace(bad_name, correct_name)
|
|
return res |