我正在尝试使用正则表达式来解析我拥有的模板。我想找到_stop
标签的_start
标签。我需要找到特定的,因为可以有嵌套_stop
和_start
标签。
我正在使用的正则表达式是
/{(.*?)_start}.*{(\1_stop)}/s
把它扔进一个preg_match
和模板
<div data-role="collapsible-set" class="mfe_collapsibles" data-theme="c" data-inset="false">
{MakeAppointment_start}
<div id="appointmentHeading" data-action-id="appointmentNext" data-action-text="Next" data-a data-role="collapsible" data-collapsed="true" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d" data-iconpos="right">
<h3 class="collapsibleMainHeading">New {AppointmentTerm}</h3>
<p>
{AppointmentForm}
</p>
</div>
{MakeAppointment_stop}
{RegisterSection_start}
<div id="registerHeading" class="preRegistration" data-action-id="register" data-action-text="Register" data-role="collapsible" data-collapsed="true" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d" data-iconpos="right">
<h3 class="collapsibleMainHeading">Register</h3>
<p>
{RegisterForm}
</p>
</div>
{RegisterSection_stop}
<div data-role="collapsible" class="preRegistration" data-collapsed="true" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d" data-iconpos="right">
<h3 class="collapsibleMainHeading">Login</h3>
<p>
{LoginForm}
</p>
</div>
</div>
</div>
结果是
Array
(
[0] => {MakeAppointment_start}
<div id="appointmentHeading" data-action-id="appointmentNext" data-action-text="Next" data-a data-role="collapsible" data-collapsed="true" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d" data-iconpos="right">
<h3 class="collapsibleMainHeading">New {AppointmentTerm}</h3>
<p>
{AppointmentForm}
</p>
</div>
{MakeAppointment_stop}
[1] => MakeAppointment
[2] => MakeAppointment_stop
)
索引 0 是正确的,但 1 和 2 不正确。1 应该有注册标签和内容,2 不应该存在。
我在这里做错了什么?