[CentralOH] Removing Punctuation: Replace Punctuation With Spaces

Eric Floehr eric at intellovations.com
Tue Jan 21 13:02:56 CET 2014


In other words (works in Python 2 and Python 3):

>>> import re
>>> import string
>>> punctuation_re = re.compile('[' + string.punctuation + ']')
>>> S = "Some, string! With punctuation."
>>> punctuation_re.sub(' ', S)
'Some  string  With punctuation '




On Tue, Jan 21, 2014 at 12:51 AM, Chris Folsom <jcfolsom at pureperfect.com>wrote:

>
> ?
>
> http://docs.python.org/2/howto/regex.html#search-and-replace
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20140121/66505459/attachment.html>


More information about the CentralOH mailing list