Created
June 10, 2019 10:03
-
-
Save Ch3mjor/3d34da1b4d0f4cb2c5a715b9dcd9a2a8 to your computer and use it in GitHub Desktop.
Python Regex Expression to remove special characters (,) and (')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is code to remove "," and "'" in code | |
#importing regex module | |
import re | |
#Final Storage array | |
final_name = [] | |
#Defining our regex that will remove commas(,) and apostrophes('), however it will ignore spaces | |
#This is a test / example code, replace with your own | |
names = ["Cow","Chick'en", "Crick,et", "Bu'll", "She,e,p"] | |
#The regex | |
pattern2 = re.compile(r'[^a-zA-Z0-9\s]+') | |
#Looping over the values in the names list to remove the characters and substitute them. | |
for name in names: | |
result3 = pattern2.sub("", name) | |
final_name.append(result3) | |
print(final_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment