How to clean a string from non alphabets and space characters in Python

1 Answer

0 votes
import re

s = 'python, #java@ !c ^&cpp (*)php.'

pattern = re.compile(r'[^a-zA-Z ]+')
s = re.sub(pattern, '', s)

print(s)



'''
run:
    
python java c cpp php

'''

 



answered Oct 28, 2020 by avibootz
...