substr vs regex

David Cantrell david at cantrell.org.uk
Thu Sep 6 12:14:29 BST 2007


On Mon, Sep 03, 2007 at 11:44:53AM +0200, Abigail wrote:
> On Mon, Sep 03, 2007 at 10:26:12AM +0100, alex at owal.co.uk wrote:
> > Imagine, say, someone wanted the last three characters of a string. They
> > might use a regex /(...)$/ or substr($variable, -3)
> substr() is far more efficient than using a regexp.

Aye.

>                                                     The speed of the
> substr() solution is independent of the length of $variable

Only true for constant-width character sets.  This is why UTF-8 is a
stupid stupid design.

-- 
David Cantrell | top google result for "internet beard fetish club"

Us Germans take our humour very seriously
  -- German cultural attache talking to the Today Programme,
     about the German supposed lack of a sense of humour, 29 Aug 2001


More information about the london.pm mailing list