'string'.strip(chars)-like function that removes from the middle?

Calvin Spealman ironfroggy at socialserve.com
Mon Jun 16 12:36:08 EDT 2008


On Jun 16, 2008, at 12:58 PM, Ethan Furman wrote:

> Greetings.
>
> The strip() method of strings works from both ends towards the middle.
> Is there a simple, built-in way to remove several characters from a  
> string no matter their location? (besides .replace() ;)
>
> For example:
> .strip --> 'www.example.com'.strip('cmowz.')
> 'example'
> .??? --> --- 'www.example.com'.strip('cmowz.')
> 'exaple'

 >>> re.sub('|'.join('cmowz.'), "www.example.com")
'.exaple.'

> --
> Ethan
>
> --
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list