Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

remove special characters from string python

import re
re.sub('[^A-Za-z0-9]+', '', mystring)
Comment

remove special characters from string python

import re
# only remove special charactors but not white spaces
re.sub('[^A-Za-z0-9]+ ', '', mystring)
# remove special charactors and white spaces as well
re.sub('[^A-Za-z0-9]+', '', mystring)
Comment

remove special characters from string python

>>> string = "Special $#! characters   spaces 888323"
>>> ''.join(e for e in string if e.isalnum())
'Specialcharactersspaces888323'
Comment

python remove special characters from list

import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub('[^a-zA-Z0-9]+', '', _) for _ in my_list]
Comment

remove special characters from string with for loop python

text = "I! want, to? eat."
chars = ".!,?"
for i in range(len(chars)):         #can't use len() alone b/c int obj is not iterable
    text = text.replace(chars[i], "")
    
print(text)     #I want to eat
Comment

remove special characters from string in python

''.join(i for i in string if i.isaplha()
Comment

PREVIOUS NEXT
Code Example
Python :: list of dict values 
Python :: python game example 
Python :: rock paper scissors python 
Python :: how to use .format in python 
Python :: python file to array 
Python :: title tikinter 
Python :: extract a column from a dataframe in python 
Python :: urllib download file to folder 
Python :: python absolute path 
Python :: how to print a string in python 
Python :: hash() python 
Python :: Print First 10 natural numbers using while loop 
Python :: python int to bytes 
Python :: even numbers from 1 to 100 in python 
Python :: how to find the transpose of a matrix in python 
Python :: install chrome driver python 
Python :: how to check all the elements in a list are even or not 
Python :: pandas row sum 
Python :: python get line number x in file 
Python :: max int python 
Python :: how to split a string with newline in python 
Python :: python create a dictionary of integers 
Python :: update nested dictionary python 
Python :: python do something while waiting for input 
Python :: read list from txt python 
Python :: python openpyxl csv to excel 
Python :: python string cut 
Python :: python for loop with step 
Python :: numpy create array with values in range 
Python :: if-else 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =