Regex replace multiple punctuation in python -
i find multiple occurrences of exclamation marks, question marks , periods (such !!?!, ...?, ...!) , replace them final punctuation.
i.e. !?!?!? become ?
and ....! become !
is possible?
text = re.sub(r'[\?\.\!]+(?=[\?\.\!])', '', text) that is, remove sequence of ?!. characters going followed ?!. character.
[...] character class. matches character inside brackets.
+ means "1 or more of these".
(?=...) lookahead. looks see going come next in string.
Comments
Post a Comment