I've been searching for quite some time now yet I can not find any explanation on the subject.
If I have a string, say: u'àaeëß35+{}"´'
. I want all non-alphanumeric charachters removed (however, I want à, ë, ß
etc. kept.
I'm fairly new to Python and I could not figure out a regex to perform this task. Only other solution I can think of is having a list with the chars I want to remove and iterating through the string replacing them.
What is the correct Pythonic solution here?
Thank you.
In [63]: s = u'àaeëß35+{}"´'
In [64]: print ''.join(c for c in s if c.isalnum())
àaeëß35
What about:
def StripNonAlpha(s):
return "".join(c for c in s if c.isalpha())
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