stripping characters with regex
Mike C. Fletcher
mcfletch at rogers.com
Wed Jan 22 22:26:18 EST 2003
>>> import string
>>> t = string.maketrans( "", "" )
>>> mystring = """ this\\ thing / 'is' "bigger" than \\ the / two 'of'
"us"."""
>>> string.translate( mystring, t, "\\/'\"" )
' this thing is bigger than the two of us.'
>>>
HTH,
Mike
Jeff Sacksteder wrote:
>I need urgent assistance. I'm cleaning up text strings containing ' ,",\ and
>/ characters which are giving an enormous headache.
>
>I have a little function like this that doesn't do what I had in mind.
>
>def clean_text(y):
> # match any number of occurrances of these four characters
> clean = re.compile('(\\|\'|\"|\/)')
> # replace them when found with nothing - effectively deleting them
> return clean.sub( '',y)
>
>Suggestions welcome, example code cheerfully accepted!
>
>
>
--
_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
More information about the Python-list
mailing list