Regular expression for nested tags


Regular expression for nested tags



I am developing an extension to highlight some custom scripting code and I need a regular expression that can capture the text between <> (including the outer tags and nested)



example link: https://regex101.com/r/7AkKRU/1



or



small demo (content needed to be capture will be commented):


IF !(<isempty <ctag.add_sub>>) //<isempty <ctag.add_sub>>
if (<ctag0.add_sub_page>) //<ctag0.add_sub_page>
local.index=<eval 14*<ctag.add_sub_page>> //<eval 14*<ctag.add_sub_page>>
endif
local.sub=<LDB.Row.<dctag.add_sub>.subsection> //<LDB.Row.<dctag.add_sub>.subsection>
LDB.query "SELECT rowid,description FROM <ctag.add_mode> WHERE subsection = '<local.sub>'" //<ctag.add_mode> <local.sub>
dtext 516 45 0480 Page (<eval <ctag0.add_sub_page>+1>/<eval (<ldb.row.numrows>/14)+1>) //<eval <ctag0.add_sub_page>+1> <eval (<ldb.row.numrows>/14)+1>
for 0 13
local.desc=<ldb.row.<dlocal.num>.description> //<ldb.row.<dlocal.num>.description>
if (<dlocal.num>< <ldb.row.numrows>) //<dlocal.num> <ldb.row.numrows>
button 760 <dlocal.dy> 4005 4007 1 0 <eval 100000+<dlocal.rowid>> //<dlocal.dy> <eval 100000+<dlocal.rowid>>
endif
endfor
IF (<ldb.row.numrows> > <eval <local.index>+14>) //<ldb.row.numrows> <eval <local.index>+14>
endif
endif



At the moment I have the following regex (don't remember where I copied from, sorry):
(?=<)(?:(?=.?<(?!.?1)(.>(?!.2).))(?=.?>(?!.?2)(.)).)+?.?(?=1)[^<](?=2$)



It works fine, but when the > is the last element of the line it grabs extra content.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages