I am trying to replace all the special characters and spaces in the string with only single '-'
For example:
Input: "Games & Fun"
Output: "Games-Fun"
I tried
>>> re.sub('[&" "]', '-', "Games & Fun")
'Games---Fun'
But I want "Games-Fun" only.
Can anyone help me with this?
>>> import re
>>> text = "Games & Fun"
>>> re.sub(r'\W+', '-', text)
'Games-Fun'
>>> re.sub(r'[&\s]+', '-', "Games & Fun")
'Games-Fun'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With