我正在尝试在受控脚本情况下使用preg-replace删除不必要的注释,但我的regex是不正确的。有人知道我的正则表达式有什么问题吗?(我有Apache/2.0.54和PHP/5.2.9
之前:
// Bla Bli Blue Blow Bell Billy Bow Bye
script var etc (); // cangaroo cognac codified cilly celine cocktail couplet
script http://blaa.org // you get the idea!之后:
script var etc ();
script http://blaa.org问题:使用什么正则表达式?
# when comment starts on a new line, delete this entire line
# find [a new line] [//] [space or no space] [comment]
$buffer = preg_replace('??', '??', $buffer);
# when comment is halfway in script ( // comment)
# find [not beginning of a line] [1 TAB] [//] [1 space again] [comment]
$buffer = preg_replace('??', '??', $buffer);任何和所有的建议都会得到我的重视,因为我离解开这个谜语如此之近!
发布于 2010-12-14 02:45:42
试试这个正则表达式:
/(?<!http:)\/\/[^\r\n]*/不过要小心,考虑如下字符串:
<!--
// not a comment -->或
/*
// not a comment */和
var s = "also // not // a // comment";你可能想要绕过https://...和ftp://...等。
https://stackoverflow.com/questions/4432297
复制相似问题