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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -