【发布时间】:2014-10-31 12:40:40
【问题描述】:
我正在努力使用正则表达式,但无法使其正常工作。 我已经尝试过: SO question,online tool,
$text = preg_replace("%/\*<##>(?:(?!\*/).)</##>*\*/%s", "new", $text);
但是没有任何效果。 我的输入字符串是:
$input = "something /*<##>old or something else</##>*/ something other";
预期结果是:
something /*<##>new</##>*/ something other
【问题讨论】:
-
您没有前瞻掩码
(.)匹配所有的量词。因此,它只接受您的 cmets 中的一个字符的字符串。同样,仅替换为new不会重新实例化/*<##>评论标记。