The list is a = ['Aeroplane','Ramanujan','World-king','Pizza/Burger']
I am trying to replace the items(with -, /) in the list with Pizza_Burger and World_king . Whatever the symbol is should be replaced by and underscore.
Here is my code:
import re
def replaceStrings(arg):
txt =arg
res = re.search(r'(?i)\b([a-z][a-z0-9_]*)([/-]+)([a-z][a-z0-9_]*)\b', txt)
if res:
pp = reg.sub(r'\1_\2',txt)
print(pp)
return pp
for i in a:
replaceStrings(i)
But I am not getting the desired output. What is wrong in my regex. I am a beginner in regex. Thank you