我在尝试让这个正则表达式工作时遇到了困难。我想要做的就是删除 block 注释。这是我到目前为止所拥有的,但我无法摆脱最后的 */
。
$string = 'this is a test /*asdfa */ ok then';
$pattern = '/\/\*([^\*\/]*)/i';
$replacement = '';
echo preg_replace($pattern, $replacement, $string);
//this is a test */ ok then
我们将不胜感激。
最佳答案
使用与 /
不同的分隔符——这会让人感到困惑。
怎么样'#/\*.+?\*/#s'
;
关于php - 通过正则表达式删除 block 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4207096/