Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiently Strip Out Punctuation but not ".com"

Tags:

python

string

I found this thread: Best way to strip punctuation from a string in Python

But was hoping to come up with a way to do this except not to strip out the periods in links. So if the string is

I love using stackoverflow.com on Fridays, Saturdays and Mondays!

It would return

I love using stackoverflow.com on Fridays Saturdays and Monday

In fact ideally I would be able to pass in a list of common link endings like .com, .net, .ly etc.

like image 442
JiminyCricket Avatar asked Jan 28 '26 16:01

JiminyCricket


1 Answers

You can use negative look-aheads:

[,!?]|\.(?!(com|org|ly))
like image 113
Jacob Avatar answered Jan 31 '26 06:01

Jacob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!