<?xml version="1.0" encoding="windows-1252"?>
<node id="240652" title="Re: Inefficient regex" created="2003-03-05 13:40:15" updated="2005-06-08 16:42:10">
<type id="11">
note</type>
<author id="28290">
sutch</author>
<data>
<field name="doctext">
This:&lt;br&gt;
&lt;code&gt;(.*?)\s*(.*?)\s*&lt;/code&gt;&lt;br&gt;
can be problematic.  Since LABEL and PARAMETER must not contain spaces, try replacing that portion with something like:&lt;br&gt;
&lt;code&gt;([^\s]+)\s+([^\s]+)?&lt;/code&gt;&lt;p&gt;

I'd also suggest that you change *? to simply *, since * denotes 0 or more occurances.&lt;p&gt;

Probably the biggest problem is the:&lt;br&gt;
&lt;code&gt;(.+?)&lt;/code&gt;&lt;br&gt;
which occurs just before:&lt;br&gt;
&lt;code&gt;&lt;%end_\1%&gt;&lt;/code&gt;&lt;br&gt;
and matches to the end of the string, which then causes the regex engine to backtrack each time it cannot find each "end" tag.&lt;p&gt;

You may also want to take a look at the book "Mastering Regular Expressions" by Jeffrey E. Friedl.  See [id://21667|Mastering Regular Expressions] for a review.

</field>
<field name="root_node">
240648</field>
<field name="parent_node">
240648</field>
</data>
</node>
