One simple way:

>>> s = "Adam'sApple"
>>> x = s.replace("'", "")
>>> print x
'AdamsApple'

... or take a look at regex substitutions.

Answer from miku on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-removing-unwanted-characters-from-string
Remove Special Characters from String in Python - GeeksforGeeks
July 11, 2025 - re.sub() function from re module allows you to substitute parts of a string based on a regex pattern. By using a pattern like [^a-zA-Z0-9], we can match and remove all non-alphanumeric characters. This method is highly efficient, making it ideal for cleaning complex strings.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-remove-character-from-string
How to Remove Characters from a String in Python | DigitalOcean
Remove characters from a Python string with replace(), translate(), re.sub(), and slicing. Compare methods, see examples, and pick the right approach.
Discussions

parsing - Removing unwanted characters from a string in Python - Stack Overflow
I have some strings that I want to delete some unwanted characters from them. For example: Adam'sApple ----> AdamsApple.(case insensitive) Can someone help me, I need the fastest way to do it, c... More on stackoverflow.com
🌐 stackoverflow.com
How do I remove remove stuff like (. , ' *) from a string?
You can use isalnum() to remove special characters. The string method .isalnum() returns True or False if a string is all alphanumeric characters. With this we can write a comprehension that loops over the characters in the string and only keep the alphanumeric characters. I think the regex method is more efficient, especially for really big strings, but you have to know all the characters you want to remove, with isalnum you don't. On the flipside you don't have to add another import if you use isalnum. So it depends on the situation for which method you should choose (re vs isalnum). s = "Bob 'hit' a ball, the hit BALL flew far after it was hit." # Remove all special characters unless it is a space # Replace "hit" with "sample" new_s = "".join(char for char in s if char.isalnum() or char == " ").replace("hit", "sample") print(new_s) >>>Bob sample a ball the sample BALL flew far after it was sample More on reddit.com
🌐 r/learnpython
14
1
August 6, 2021
Python - remove unwanted characters from a string - Stack Overflow
I have string like below Which contains non ascii characters and other special characters: “Projected Set-tled Balan&ce†456$ How to remove all those unwanted characters and get a clean ... More on stackoverflow.com
🌐 stackoverflow.com
March 29, 2019
remove all possible unwanted characters from python string at once - Stack Overflow
-3 Remove unwanted non-printable characters from large CSV files with millions of records -in Python 3 or 2.7 More on stackoverflow.com
🌐 stackoverflow.com
October 2, 2018
🌐
w3resource
w3resource.com › python-exercises › string › python-data-type-string-exercise-89.php
Python: Remove unwanted characters from a given string - w3resource
# Define a function to remove unwanted ... unwanted character for i in unwanted_chars: # Use the replace() method to remove occurrences of the unwanted character from the string str1 = str1.replace(i, '') # Return the modified string ...
Top answer
1 of 9
6

One simple way:

>>> s = "Adam'sApple"
>>> x = s.replace("'", "")
>>> print x
'AdamsApple'

... or take a look at regex substitutions.

2 of 9
6

Here is a function that removes all the irritating ascii characters, the only exception is "&" which is replaced with "and". I use it to police a filesystem and ensure that all of the files adhere to the file naming scheme I insist everyone uses.

def cleanString(incomingString):
    newstring = incomingString
    newstring = newstring.replace("!","")
    newstring = newstring.replace("@","")
    newstring = newstring.replace("#","")
    newstring = newstring.replace("$","")
    newstring = newstring.replace("%","")
    newstring = newstring.replace("^","")
    newstring = newstring.replace("&","and")
    newstring = newstring.replace("*","")
    newstring = newstring.replace("(","")
    newstring = newstring.replace(")","")
    newstring = newstring.replace("+","")
    newstring = newstring.replace("=","")
    newstring = newstring.replace("?","")
    newstring = newstring.replace("\'","")
    newstring = newstring.replace("\"","")
    newstring = newstring.replace("{","")
    newstring = newstring.replace("}","")
    newstring = newstring.replace("[","")
    newstring = newstring.replace("]","")
    newstring = newstring.replace("<","")
    newstring = newstring.replace(">","")
    newstring = newstring.replace("~","")
    newstring = newstring.replace("`","")
    newstring = newstring.replace(":","")
    newstring = newstring.replace(";","")
    newstring = newstring.replace("|","")
    newstring = newstring.replace("\\","")
    newstring = newstring.replace("/","")        
    return newstring
🌐
freeCodeCamp
freecodecamp.org › news › how-to-remove-a-specific-character-from-a-string-in-python
How to Remove a Specific Character from a String in Python
December 7, 2022 - Then, specify the group of characters you want to remove (in this case, the ! and ? characters), along with the characters you want to replace them with. In this case, the replacement is an empty character: import re my_string = "Hi!? I!? love!? Python!?" my_new_string = re.sub('[!?]',"",my_string) print(my_new_string) # output # Hi I love Python
🌐
Reddit
reddit.com › r/learnpython › how do i remove remove stuff like (. , ' *) from a string?
r/learnpython on Reddit: How do I remove remove stuff like (. , ' *) from a string?
August 6, 2021 -

I have a string:

"Bob 'hit' a ball, the hit BALL flew far after it was hit."

And I want to replace the word 'hit' by 'sample'.

How do I do that when the word gets immediately followed/preceded by stuff like (. , ' *)

Edit: I know using replace() will work but I don't know what special characters there will be in the string. Some strings had characters like ( - [ / + .

🌐
STechies
stechies.com › python-remove-character-from-string
How to Remove Characters from a String in Python?
In this article, we have explained significant string manipulation with a set of examples. In the following example, we are using replace() function with for loop to check unwanted characters and replace them one by one with a blank character.
Find elsewhere
🌐
Medium
medium.com › @ryan_forrester_ › remove-special-characters-from-strings-in-python-complete-guide-53651c8163d9
Remove Special Characters from Strings in Python: Complete Guide | by ryan | Medium
January 7, 2025 - The `replace()` method works well when you know exactly which characters you want to remove. The `strip()` method is perfect for cleaning up the beginning and end of strings.
🌐
TutorialsPoint
tutorialspoint.com › python-removing-unwanted-characters-from-string
Python - Removing unwanted characters from string
August 1, 2023 - My Name Is, John" to_be_removed = "!," final_string =unwanted_string_words(whole_string, to_be_removed) print(final_string) ... In this method we will use the regular expression module to remove the characters from the string.
🌐
Learn By Example
learnbyexample.org › removing-unwanted-characters-from-a-string-in-python
Removing Unwanted Characters from a String in Python - Learn By Example
April 16, 2024 - The function you provide defines a condition for keeping characters. filter() then creates an iterator that only includes characters from the original string where your function returns True. original_string = "Hello, world! How's everything? Good, I hope." new_string = ''.join(filter(lambda x: x not in ",.!?'", original_string)) print(new_string) # Output: "Hello world Hows everything Good I hope" In the example provided, a lambda function is used to check whether each character exists within the set of unwanted characters (“,.!?'”).
🌐
Codecademy
codecademy.com › article › remove-characters-from-a-python-string
How to Remove Characters from a String in Python | Codecademy
Fortunately, Python offers several simple yet powerful ways to remove multiple characters from a string: ... Let’s take a look at them one by one. The replace() method can be used multiple times in sequence to remove more than one character. ... We chained multiple replace() calls to remove each unwanted character one by one.
🌐
Real Python
realpython.com › python-strip
How to Strip Characters From a Python String – Real Python
October 22, 2025 - If you don’t provide any arguments to the method, then .strip() removes all leading and trailing whitespace characters, leaving any whitespace within the string untouched: ... When you call .strip() on a string object, Python removes the leading ...
🌐
Stack Abuse
stackabuse.com › python-how-to-remove-a-character-from-a-string
Python: How to Remove a Character from a String
October 14, 2023 - The most common way to remove a character from a string is with the replace() method, but we can also utilize the translate() method, and even replace one or more occurrences of a given character. The string class provides a replace() method that replaces a character with another.
🌐
Python Guides
pythonguides.com › remove-character-from-string-python
Python Remove Multiple Characters From String
August 19, 2025 - The first method I often use is Python’s built-in replace() function. It’s easy and works perfectly when you only need to remove a few known characters. # Example: Cleaning up a US phone number string text = "(123)-456-7890" # Remove parentheses and hyphens cleaned = text.replace("(", "").replace(")", "").replace("-", "") print("Original:", text) print("Cleaned :", cleaned)
🌐
Quora
quora.com › How-do-I-remove-all-special-characters-in-a-string-in-Python
How to remove all special characters in a string in Python - Quora
Answer (1 of 5): There are numerous ways to accomplish this. To remove, say, all the a’s from a string, one can use the replace() string method: [code]>>> s = 'A man, a plan, a canal: Panama' >>> s = s.replace('a', '') >>> s 'A mn, pln, cnl: Pnm' [/code]One could also “explode” the string ...
🌐
Delft Stack
delftstack.com › home › howto › python › remove special characters from string python
How to Remove Special Characters From the String in Python | Delft Stack
February 2, 2024 - Python ScipyPythonPython TkinterBatchPowerShellPython PandasNumpyPython FlaskDjangoMatplotlibDockerPlotlySeabornMatlabLinuxGitCCppHTMLJavaScriptjQueryPython PygameTensorFlowTypeScriptAngularReactCSSPHPJavaGoKotlinNode.jsCsharpRustRubyArduinoMySQLMongoDBPostgresSQLiteRVBAScalaRaspberry Pi ... Remove Special Characters From the String in Python Using str.translate() and str.maketrans() Methods
🌐
Linux Hint
linuxhint.com › remove-special-characters-string-python-2
Remove Special Characters from String Python – Linux Hint
In Python, another efficient way to eliminate the special characters from the provided input is using the “translate()” method. It uses a mapping table for changing all characters that exist in the table’s key positions with the character that exists in the table’s value position.
🌐
Stack Overflow
stackoverflow.com › questions › 52603503 › remove-all-possible-unwanted-characters-from-python-string-at-once
remove all possible unwanted characters from python string at once - Stack Overflow
October 2, 2018 - If you need this text to do some sort of sentiment analysis, then you might also like to remove special characters like \n, \r, etc, which can be done by first escaping the escape characters, and then replacing them with the help of regex. from newspaper import Article import re article = Article('https://www.abcd....vnn.com/dhdhd') article.download() article.parse() article.nlp() text = article.summary text = text.encode('ascii',errors='ignore') text = str(text) #converts `\n` to `\\n` which can then be replaced by regex text = re.sub('\\\.','',text) #Removes all substrings of form \\. print (text)