Php 匹配HTML注释内容的正则表达式

Php 匹配HTML注释内容的正则表达式,php,regex,Php,Regex,例如,如果我有以下代码: <!--start-here--> <div>My Cool Content!!!</div> <h1>Headerrr</h1> <!--end-here--> <div>Other Content</div> 如何使用正则表达式来获取介于和之间的内容 因此,我的输出是: <div>My Cool Content!!!</div> <h1&g

例如,如果我有以下代码:

<!--start-here-->
<div>My Cool Content!!!</div>
<h1>Headerrr</h1>
<!--end-here-->
<div>Other Content</div>
如何使用正则表达式来获取介于和之间的内容

因此,我的输出是:

<div>My Cool Content!!!</div>
<h1>Headerrr</h1>
你不需要正则表达式

$str = '<!--start-here-->
        <div>My Cool Content!!!</div>
        <h1>Headerrr</h1>
        <!--end-here-->
        <div>Other Content</div>';

$return = explode('<!--start-here-->', $str);
$return = explode('<!--end-here-->', $return[1]);
$return = $return[0];
还是用正则表达式

$str = preg_match('/<!--start-here-->[\s\S]*<!--end-here-->/', $str, $return);
$return = $return[0];
你不需要正则表达式

$str = '<!--start-here-->
        <div>My Cool Content!!!</div>
        <h1>Headerrr</h1>
        <!--end-here-->
        <div>Other Content</div>';

$return = explode('<!--start-here-->', $str);
$return = explode('<!--end-here-->', $return[1]);
$return = $return[0];
还是用正则表达式

$str = preg_match('/<!--start-here-->[\s\S]*<!--end-here-->/', $str, $return);
$return = $return[0];
试试这个

<!--start-here-->(.|\n)*<!--end-here-->
试试这个

<!--start-here-->(.|\n)*<!--end-here-->
这应该可以做到:/.*/m。 像这样使用它:/.*/m.exechtmlCode

这应该可以做到:/.*/m。 像这样使用它:/.*/m.exechtmlCode

这应该行得通


这应该会起作用

这些标记是重复的还是只是一个块?开始标记和结束标记只出现一次/*?/im这些标记是重复的还是只是一个块?开始标记和结束标记只出现一次/*?/im如果你需要关于RegEx的信息,请在这里询问,现在我不明白为什么;没有需要转义的字符。。。如果需要修改,只需使用这个:/[].[]?[]/imsI认为。除了换行符外,其他都匹配吗?如果是,它是否应该说。\n*。。。?不过,为了公平起见,我不确定php中如何处理点字符。匹配一切;m after/i代表Multyline如果您需要关于RegEx的信息,请在此处询问,现在我不明白为什么不;没有需要转义的字符。。。如果需要修改,只需使用这个:/[].[]?[]/imsI认为。除了换行符外,其他都匹配吗?如果是,它是否应该说。\n*。。。?不过,为了公平起见,我不确定php中如何处理点字符。匹配一切;m/i后的m代表multyline