php 函数 preg_replace 正则表达式不起作用,语法问题
我试图在受控脚本情况下使用 preg-replace 删除不必要的注释,但我的正则表达式不正确。有人知道我的正则表达式有什么问题吗? (我有 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);
任何和所有建议都将被我重视+1,因为我非常接近解决这个谜语!
im trying to remove unnessary comments with preg-replace in controlled script situations, but my regex is incorrect. Anyone any ideas whats wrong with my regex? (i have Apache/2.0.54 & PHP/5.2.9
BEFORE:
// 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!
AFTER:
script var etc ();
script http://blaa.org
PROBLEM: what regex to use?
# 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);
Any and All suggestions will be valued +1 by me, cuase im so darn close to solve this riddle!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个正则表达式:
不过要小心,考虑像这样的字符串:
or
and
你可能想解决
https://...
和ftp://...
ETC。Try this regex:
Be cautious though, consider strings like:
or
and
And you might want to work around
https://...
andftp://...
etc.