I have a dictionary of words I want to replace.
preprocess_pattern = {r" AND ": r" & ",
r" O\A ": r" O/A ",
r" D\B ": r" O/A ",
r" D/B ": r" O/A "}
def preprocess_rules(text):
for detect_pattern, replace_pattern in preprocess_pattern .items():
text = re.sub(detect_pattern, replace_pattern, str(text))
return text
preprocess_rules('AMAZON O\A MICROSOFT')
It gives me a result of 'AMAZON O\A MICROSOFT'; with two slashes(). The O\A didn't replace to O/A. Was wondering what is causing this issue.