Greetings All,
I need to optimize a RegEx I am using to parse template tags in my CMS. A tag can be either a single tag or a matching pair. An example of some tags:
{static:input:title type="input"}
{static:image:picture}<img src="{$img.src}" width="{$img.width}" height="{$img.height"} />{/static:image:picture}
Here is the RegEx I currently have that properly selects what I need but I ran it through the RegexBuddy debugger and it takes tens of thousands of steps to do one match if the HTML page is quite large.
{static([\w:]*)?\s?(.*?)}(?!"|')(?:((?:(?!{static\1).)*?){/static\1})?
When this matches a tag, Group 1 is the parameters which is all the colon separated words. Group 2 is the parameters. And Group 3 (If it's a tag pair) is the content between each tag.
I'm also having problems when I stick these tags inside my conditional tags as well. Something like this doesn't match group 2 properly (Group 2 should be blank in both the matched tags below):
{if "{static:image:image1}"!=""}
<a href="{static:image:image1}" rel="example_group" title="Image 1"></a></li>
{/if}
Another situation that needs to work is have the same tag being used twice in a row but the first instance being used a single tag and the second being used as a tag pair. So something like this:
{static:image:picture}
{static:image:picture}<img src="{$img.src}" width="{$img.width}" height="{$img.height"} />{/static:image:picture}
There needs to be two separate matches. The first match would have only group 1. The second match would have group 1 and group 3.
If anyone needs more information, please don't hesitate to ask. The CMS is built in PHP using the CakePHP framework.
Big kudos to anyone who can help me out :D!