I want to remove extra r and n from this string. I tried regex. Not sure if regex or some other method would be helpful here.
This is the code I am trying to use import re
text = "r n r n r nFamily Medical History new r n r n r r r Roger nRobert n nDawson n49 nyears old , right shoulder"
regex_pattern = re.compile(r'\s[rn]\s')
matches = regex_pattern.findall(text)
for match in matches:
text = text.replace(match," ")
print(text)
Current Output:
r nFamily Medical History new Roger nRobert nDawson n49 nyears old , right shoulder
we still see many r n. Also wondering how to remove 'n' from n49, nyears and remove first 'n' from Dawson without removing last 'n'
Expected Output:
Family Medical History new Roger Robert Dawson 49 years old , right shoulder