I am trying remove all punctuation except comma. I am doing the following
import re
st = "here comes, 'lot of', cover"
st = re.sub(r'[^\w\s],', '', st )
But it also removes the comma.
CodePudding user response:
import re
st = "here comes, 'lot of', cover"
print(re.sub(r"[^\w\d,\s] ",'',st))
Specify all the elements you don't want removed,after ^
and with in square brackets i.e., matches anything except
CodePudding user response:
Try doing [^\w\s,]
.
Example: https://regexr.com/6iss3