Remove Punctuations From a String in Python Using Regular Expressions
(Last Updated On: 13/01/2023)
Python Program to Remove Punctuations From a String Using Regular Expressions
# Python Program to Remove Punctuations From a String Using Regular Expressions
import re
sample_text = "Hello, Newtum !is# ^the*@ b)e$st^ platform>< to Learn P>ython??"
print("Input String: " + sample_text)
# logic to remove punctuations from a string
sample_text = re.sub(r'[^\w\s]','',sample_text)
print("Final String: " + sample_text)
Output:
Input String: Hello, Newtum !is# ^the*@ b)e$st^ platform>< to Learn P>ython??
Final String: Hello Newtum is the best platform to Learn Python