substr vs regex

alex@owal.co.uk alex at owal.co.uk
Mon Sep 3 10:26:12 BST 2007


Imagine, say, someone wanted the last three characters of a string. They
might use a regex /(...)$/ or substr($variable, -3)

personally I recommend the former because it is more readable, but others
have recommended substr to because you "dont need to bring out the big
guns". (However no one could actually remember the substr function)

Is one of these significantly more efficient than the other? Ok ok, so I
could probably write a test in a few minutes but asking you guys is more
interesting.

Comments?

Alex




More information about the london.pm mailing list