How to remove special characters and numbers from string ! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to remove special characters and numbers from string !

14th Dec 2020, 3:53 AM
Mohammed Moin
Mohammed Moin - avatar
6 Answers
+ 4
Mohammed Moin Use Regex to get only Alphabets from String.
14th Dec 2020, 3:55 AM
A͢J
A͢J - avatar
+ 4
Mohammed Moin You can learn Regex using this cheat sheet https://www.sololearn.com/post/815377/?ref=app
14th Dec 2020, 4:43 AM
A͢J
A͢J - avatar
+ 3
Mohammed Moin No need to remove. You can just get only Alphabets from the string using Regex ----------- import re patt = "[a-zA-Z]" str1 = "-₹+₹+₹&#@+&&abdba AGH" print (re.findall(patt, str1)) Remember here findall returns array so you need to convert in string.
14th Dec 2020, 4:31 AM
A͢J
A͢J - avatar
+ 1
I want to remove both special characters and numbers
14th Dec 2020, 3:58 AM
Mohammed Moin
Mohammed Moin - avatar
+ 1
It is also removing space which I need it
14th Dec 2020, 4:34 AM
Mohammed Moin
Mohammed Moin - avatar
0
Use Regex.
14th Dec 2020, 10:59 AM
Daniel Tobi Nyorere
Daniel Tobi Nyorere - avatar