php - Need To Optimize RegEx For A Template Parser -


greetings all,

i need optimize regex using parse template tags in cms. tag can either single tag or matching pair. example of tags:

{static:input:title type="input"}  {static:image:picture}<img src="{$img.src}" width="{$img.width}" height="{$img.height"} />{/static:image:picture} 

here regex have selects need ran through regexbuddy debugger , takes tens of thousands of steps 1 match if html page quite large.

{static([\w:]*)?\s?(.*?)}(?!"|')(?:((?:(?!{static\1).)*?){/static\1})? 

when matches tag, group 1 parameters colon separated words. group 2 parameters. , group 3 (if it's tag pair) content between each tag.

i'm having problems when stick these tags inside conditional tags well. doesn't match group 2 (group 2 should blank in both matched tags below):

{if "{static:image:image1}"!=""}     <a href="{static:image:image1}" rel="example_group" title="image 1"></a></li> {/if} 

another situation needs work have same tag being used twice in row first instance being used single tag , second being used tag pair. this:

{static:image:picture} {static:image:picture}<img src="{$img.src}" width="{$img.width}" height="{$img.height"} />{/static:image:picture} 

there needs 2 separate matches. first match have group 1. second match have group 1 , group 3.

if needs more information, please don't hesitate ask. cms built in php using cakephp framework.

big kudos can me out :d!

your syntax complicated regular expressions. need context-free grammar. (read on chomsky hierarchy understand why.)

i second recommendation use existing template language (such smarty) rather inventing own.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -