On Feb 14, Michael Fowler said:

>As mentioned by a couple of people, the non-greedy version of * is one way
>of going about it:
>
>    $String =~ /^(.*?):/;
>
>A faster way, however, is to realize that what you really want is
>anything-but-a-colon followed by a colon:
>
>    $String =~ /^([^:]+):/;

As of Perl 5.6.2 (not released yet), /^(.*?):/ and /^([^:]*):/ will have
the same efficiency (read: speed).  If you're curious, currently /^.*?:/
and /^[^:]*:/ have the same speed -- it's the capturing that killed .*?,
but I have fixed that.

And personally, I'd use /([^:]*)/ instead of /^([^:]*):/, since they match
the same thing (assuming there IS a colon in the string).  Or I'd use
/(.*?):/ instead of /^(.*?):/ but whatever.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to