PHP's str_replace ?

Anjanesh Lekshminarayanan mail at anjanesh.net
Wed Sep 10 18:33:46 CEST 2008


Matthias Huening wrote:
> Matthias Huening (10.09.2008 16:07):
>> Anjanesh Lekshminarayanan (10.09.2008 15:50):
>>> In PHP, if I do
>>> str_replace(array('a', 'e', 'i', 'o', 'u'), '-', $str)
>>> it'll replace all vowels with a hyphen in string $str.
>>>
>>> Is there some equivalent in Python ?
>>
>> What about something like this:
>>
>> import re
>> new_str = re.sub('([aeiou])-', r'\1', str)
>>
>
> Sorry - I misinterpreted your question.
> Try this instead:
>
> import re
> new_str = re.sub('[aeiou]', '-', str)
Wow - this is neat. Thanks




More information about the Python-list mailing list