PHP's str_replace ?

David Thole dthole at gmail.com
Wed Sep 10 14:52:25 EDT 2008


On Sep 10, 12:20 pm, Christian Heimes <li... at cheimes.de> wrote:
> Anjanesh Lekshminarayanan wrote:
> >> import re
> >> 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.
>
> Christian

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.

-David
http://www.thedarktrumpet.com



More information about the Python-list mailing list