in reply to Inefficient regex
This:
(.*?)\s*(.*?)\s*
can be problematic. Since LABEL and PARAMETER must not contain spaces, try replacing that portion with something like:
([^\s]+)\s+([^\s]+)?
(.*?)\s*(.*?)\s*
can be problematic. Since LABEL and PARAMETER must not contain spaces, try replacing that portion with something like:
([^\s]+)\s+([^\s]+)?
I'd also suggest that you change *? to simply *, since * denotes 0 or more occurances.
Probably the biggest problem is the:
(.+?)
which occurs just before:
<%end_\1%>
and matches to the end of the string, which then causes the regex engine to backtrack each time it cannot find each "end" tag.
You may also want to take a look at the book "Mastering Regular Expressions" by Jeffrey E. Friedl. See Mastering Regular Expressions for a review.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Inefficient regex (death to dot star)
by tye (Sage) on Mar 05, 2003 at 19:45 UTC | |
by Wibble (Beadle) on Mar 05, 2003 at 21:07 UTC | |
Re: Re: Inefficient regex
by Thelonius (Priest) on Mar 05, 2003 at 19:40 UTC | |
by sutch (Curate) on Mar 05, 2003 at 20:14 UTC |
In Section
Seekers of Perl Wisdom