I currently have this line address = re.sub('[^A-Za-z0-9]+', ' ', address).lstrip() which will remove all special characters from my string address. How can I modify this line to keep #?
In order to avoid removing the hash symbol, you need to add it into the negated character class:
r'[^A-Za-z0-9#]+'
             ^
See the regex demo
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