PHP How to set the preg-groups to “non-capture” (?:…)

折月煮酒 提交于 2019-12-04 20:24:26

Just unroll the regex as

$contentHTML = preg_replace("#<!--[^-]*(?:-(?!->)[^-]*)*-->#", "", $contentHTML);

See the regex demo. Comapre with yours taking about 3 times as more steps as mine with a very short example.

Details:

  • <!-- - start of comment
  • [^-]* - 0+ non--
  • (?:-(?!->)[^-]*)* - 0+ sequences of - that is not followed with -> and then 0+ non--s
  • --> - comment end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!