stripping characters with regex

Skip Montanaro skip at pobox.com
Wed Jan 22 22:24:41 EST 2003


    Jeff> I need urgent assistance. I'm cleaning up text strings containing
    Jeff> ' ,",\ and / characters which are giving an enormous headache.

How about

    re.sub(r"""[\\'"/]""", "", y)

Example:

    >>> s = r''' "\''"//\/' '''
    >>> s
    ' "\\\'\'"//\\/\' '
    >>> re.sub(r"""[\\'"/]""", "", s)
    '  '

Skip





More information about the Python-list mailing list