所以我有一个带有这样的标志的字符串: <<-- name -->> 现在我想将它们全部替换为 ''。
我做了以下功能:
function removeFlags($output) {
$output = preg_replace('/\<<--[^-->>]+-->>/', '', $output);
return $output;
}
它适用于大多数标志,但不适用于包含数字的标志。 例如:<<-- Model -->> 将仅替换为 '',但 <<-- 360 -->> 不会被删除。
我做错了什么?
最佳答案
这应该适合您,因为您想替换特定模式之前和之后的任何内容
$output = preg_replace('/\<<--.+?-->>/', '', $output);
我认为你的模式也应该适用于数字,但是数字前后有空格吗?
关于php - 当字符串包含数字时 Preg_replace 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35697031/