如何匹配包括多行的字符串之间的所有内容?

时间:2015-03-18 11:24:26

标签: php regex

我正在编写自己的模板引擎,我正在编写循环部分,我认为我应该使用正则表达式来帮助我匹配模板中的任何循环

我想出了以下

{foreach \$list as \$item}(.+?)${\/endforeach}\s

我需要它来匹配这两个字符串和这两个字符串之间的所有内容,所以如果我的文字是

<html>
   <head>
       <title>Test</title>
   </head>
   <body>
{foreach $list as $item}
    <td>{$item}</td>
{/endforeach}
   </body>
</html>

我需要它来匹配

{foreach $list as $item}
    <td>{$item}</td>
{/endforeach}

然而,我写的正则表达式是匹配它,直到新行发生然后它停止匹配,即使我使用\ s

有谁知道出了什么问题?

0 个答案:

没有答案