PHP's str_replace ?

Grzegorz Staniak gstaniak at wp.pl
Wed Sep 10 14:59:14 EDT 2008


On 10.09.2008, David Thole <dthole at gmail.com> wroted:

>> >> new_str = re.sub('[aeiou]', '-', str)
>> > Wow - this is neat. Thanks
>>
>> But probably slower and definitely harder to understand. For simple
>> problems the str methods are usually faster than a regular expression.
>
> It's true that regular expressions are generally slower, but I
> disagree that it's hard to understand.  When dealing with text, I
> think it's an absolute must that programmers know about regular
> expressions.  I think this here is an example where even str_replace
> in Python wouldn't have worked well.

What about mystring.translate(transtable)?

GS
-- 
Grzegorz Staniak <gstaniak _at_ wp [dot] pl>
Nocturnal Infiltration and Accurate Killing



More information about the Python-list mailing list