Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
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('[email protected]#'))
print(remove_non_alphanumeric('[email protected]#ABC'))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)