in reply to Removing backtracking from a .*? regexp
How about the following?
use strict; my $target = shift || 'word'; my $re = qr/a=<(.*?$target.*?)>/; while( <DATA> ) { if (index($_, $target) >= 0 && /$re/) { #short-circuit regex! print "[$1]\n"; } }
The poor, oft-ignored index function will filter out lines that don't contain 'word' at all, probably w/fewer cycles than running a regexp. Your mileage may vary, of course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Removing backtracking from a .*? regexp
by diotalevi (Canon) on Nov 17, 2003 at 20:44 UTC | |
by Art_XIV (Hermit) on Nov 17, 2003 at 21:02 UTC | |
by BrowserUk (Patriarch) on Nov 17, 2003 at 21:30 UTC |