Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

求助一个正则表达式

{extend name="main.html"}
{block name="menu"}
<div>
    菜单继承
</div>
{/block}


{block name="left"}
<div>
    左边继承
</div>
{/block}

如上,我该如何匹配到两个{block}{/block}和他们里面的内容?
我写的{block name="(.*?)"}([sS]*){/block}会匹配到

<div>
    菜单继承
</div>
{/block}


{block name="left"}
<div>
    左边继承
</div>

而预期是想匹配

<div>
    菜单继承
</div>

<div>
    左边继承
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

正则改成惰性匹配:

{block name="(.*?)"}([sS]*?){/block}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...