I have some strings such as abc pre - school unit
or abc pre / school district
that I would need to delete additional spaces before and after hyphen and slash. These examples will become abc pre-school unit
and abc pre/school district
.
I attempted this solution, but this works just replacing either slash or hyphen with hyphen. How can I delete the spaces to get these strings?
abc pre-school unit
abc pre/school district
import re
text= ['abc pre - school unit', 'abc pre / school district']
for name in text:
tmp= re.sub("\s+[-/]\s+" , "-", name)
print(tmp)