我需要将单行注释(//...)
转换为块注释(/*...*/)
。我已经在下面的代码中实现了这个功能,但是我需要让函数跳过任何已经在块注释中的单行注释。目前它匹配任何单行注释,即使单行注释已经在块注释中。
## Convert Single Line Comment to Block Comments
function singleLineComments( &$output ) {
$output = preg_replace_callback('#//(.*)#m',
create_function(
'$match',
'return "/* " . trim(mb_substr($match[1], 0)) . " */";'
), $output
);
}
/* foo\n// shouldn't match\nbar */
- 您不希望它匹配第二行,但它确实匹配了。 - Alan Moore