in reply to Re: Get chars between 2 markers using regular expressions
in thread Get chars between 2 markers using regular expressions
which is more accurate but slower (because it needs to look ahead).According to this benchmark on my machine
use strict; use warnings; use Benchmark qw(:all); my $string="He0Hello~~He2World~~"; sub invertedCharclass { $string=~m/He\d([^~]+)~~/g } sub nonGreedy { $string=~m/He\d(.+?)~~/g } cmpthese (-10, { '[^~]+' => \&invertedCharclass, '.+?' => \&nonGreedy, } );
Rate [^~]+ .+? [^~]+ 236537/s -- -22% .+? 303038/s 28% --
which says, that the non-greedy matchall is even faster than the inverted character class.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Get chars between 2 markers using regular expressions
by tirwhan (Abbot) on Dec 06, 2005 at 15:16 UTC |