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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -