您好我想要删除数据中出现的所有注释标记的重复实例。
我正在使用的数据如下所述
<!-- <li><a class="topitemlink" href="/About-Us/Career-Centre.aspx">Career Centre</a></li>
<li><img alt="" width="7" height="22" src="/images/common/separator.gif" /></li>-->
<li><a class="topitemlink" href="/ContactUs">Contact Us</a> <!-- <ul class="topcontactusmenu"><li><a href="/ContactUs">Contact Us</a></li><li><a href="/Investor-Relations/Contact-the-IR-Team.aspx">Contact the IR Team</a></li><li><a href="/Media-Centre/Contact-the-Media-Team.aspx">Contact the Media Team</a></li></ul> --></li>
</ul>
</div>
<!--<a href="http://www.bizsmart.com.my/SME-Challenge/Videos" target="new" style="margin:5px; float:left;"><img width="92" height="40" src="/ABMB/media/MyLibrary/Shared/Images/bizSmart_logo.gif" alt="" /></a><a href="/sabahrun" target="new" style="margin:5px; float:left;"><img width="76" height="40" src="/ABMB/media/MyLibrary/Shared/Images/sabah-run2015_top-icon.jpg" alt="" /></a>-->
我正在使用的正则表达式只捕获第一个实例,但我希望捕获所有实例。
<!--.*\s.*-->
答案 0 :(得分:1)
答案 1 :(得分:0)
您没有指定您正在使用的语言,但php
您可以使用/<!--.*?-->/s
,即:
$html = '<!-- <li><a class="topitemlink" href="/About-Us/Career-Centre.aspx">Career Centre</a></li>
<li><img alt="" width="7" height="22" src="/images/common/separator.gif" /></li>-->
<li><a class="topitemlink" href="/ContactUs">Contact Us</a> <!-- <ul class="topcontactusmenu"><li><a href="/ContactUs">Contact Us</a></li><li><a href="/Investor-Relations/Contact-the-IR-Team.aspx">Contact the IR Team</a></li><li><a href="/Media-Centre/Contact-the-Media-Team.aspx">Contact the Media Team</a></li></ul> --></li>
</ul>
</div>
<!--<a href="http://www.bizsmart.com.my/SME-Challenge/Videos" target="new" style="margin:5px; float:left;"><img width="92" height="40" src="/ABMB/media/MyLibrary/Shared/Images/bizSmart_logo.gif" alt="" /></a><a href="/sabahrun" target="new" style="margin:5px; float:left;"><img width="76" height="40" src="/ABMB/media/MyLibrary/Shared/Images/sabah-run2015_top-icon.jpg" alt="" /></a>-->';
$html = preg_replace('/<!--.*?-->/s', '', $html);
echo $html;
/*<li><a class="topitemlink" href="/ContactUs">Contact Us</a> </li>
</ul>
</div>*/
<强>样本:强>
<强>说明强>
<!--.*?-->
Options: Case sensitive; Exact spacing; Dot matches line breaks; ^$ don’t match at line breaks; Greedy quantifiers; Regex syntax only
Match the character string “<!--” literally «<!--»
Match any single character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character string “-->” literally «-->»