Hackerss.com

hackerss
hackerss

Posted on

Python From a string remove characters that are not letter nor numbers


import re

def remove_non_alphanumeric(string):
    return re.sub(r'[^a-zA-Z0-9]', '', string)

print(remove_non_alphanumeric('abc123'))
print(remove_non_alphanumeric('abc123!@#'))
print(remove_non_alphanumeric('abc123!@#ABC'))
Enter fullscreen mode Exit fullscreen mode

Oldest comments (0)