Answers for "replace punctuation python"

1

how to find and replace all the punctuation in python strings

#import the regex library (pip install it with -> "pip install regex"
import re

test_phrase = 'This is a string! Bust it has punctuation. How can we remove it?'

#We're going to replace the punctution with a whitespace
clean = ' '.join(re.findall('[^!.?]+', test_phrase))
#         						^ Place the punctuation that you want
#								  to remove in the square brackets.
print(clean)
> 'This is a string But it has punctuation How can we remove it'
Posted by: Guest on March-24-2021
3

clean punctuation from string python

s.translate(str.maketrans('', '', string.punctuation))
Posted by: Guest on May-11-2020

Code answers related to "replace punctuation python"

Python Answers by Framework

Browse Popular Code Answers by Language