Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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'
Comment

PREVIOUS NEXT
Code Example
Python :: close turtle window python 
Python :: wait for element to be visible selenium python 
Python :: acess nvidia from docker compose 
Python :: python play mp3 in background 
Python :: how to get the angle of mouse from the center 
Python :: create pyspark session with hive support 
Python :: matplotlib wrap title 
Python :: pandas dataframe histogram 
Python :: python input comma separated values 
Python :: python sys halt 
Python :: python get command line arguments 
Python :: ImportError: Couldn 
Python :: rotate matrix 90 degrees clockwise python 
Python :: python string list to float 
Python :: click js selenium python 
Python :: turn off pycache python 
Python :: python format only 1 decimal place 
Python :: pandas to json without index 
Python :: get file extension python 
Python :: matplotlib log2 xaxis 
Python :: cv2 resize 
Python :: No default language could be detected for django app 
Python :: rotate image pyqt5 
Python :: reading a csv file in python 
Python :: python generate uid 
Python :: replace nan in pandas 
Python :: mape python 
Python :: Simulate webcam and microphone selenium 
Python :: arweave python 
Python :: python program for geometric progression 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =