'string'.strip(chars)-like function that removes from the middle?
Cédric Lucantis
omer at no-log.org
Mon Jun 16 12:39:13 EDT 2008
Hi,
> 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'
> --
I don't see any string method to do that, but you can use a regexp :
>>> re.sub('[cmowz.]', '', 'www.example.com')
'exaple'
--
Cédric Lucantis
More information about the Python-list
mailing list