Need To Optimize RegEx For A Template Parser

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:\[code\]{static:input:title type="input"}{static:image:picture}<img src="http://stackoverflow.com/questions/3887548/{$img.src}" width="{$img.width}" height="{$img.height"} />{/static:image:picture}\[/code\]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.\[code\]{static([\w:]*)?\s?(.*?)}(?!"|')(?:((?:(?!{static\1).)*?){/static\1})?\[/code\]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):\[code\]{if "{static:image:image1}"!=""} <a href="http://stackoverflow.com/questions/3887548/{static:image:image1}" rel="example_group" title="Image 1"></a></li>{/if}\[/code\]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:\[code\]{static:image:picture}{static:image:picture}<img src="http://stackoverflow.com/questions/3887548/{$img.src}" width="{$img.width}" height="{$img.height"} />{/static:image:picture}\[/code\]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!
 
Back
Top