Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php函数preg_replace regex不起作用,一个语法问题_Php_Regex_Preg Replace_Pcre - Fatal编程技术网

php函数preg_replace regex不起作用,一个语法问题

php函数preg_replace regex不起作用,一个语法问题,php,regex,preg-replace,pcre,Php,Regex,Preg Replace,Pcre,在受控脚本情况下,我试图用preg replace删除不必要的注释,但我的正则表达式不正确。有人知道我的正则表达式有什么问题吗?(我有Apache/2.0.54和PHP/5.2.9 之前: 之后: 问题:使用什么正则表达式? 任何和所有的建议都会被我重视+1,因为我很快就能解开这个谜了!试试这个正则表达式: /(?<!http:)\/\/[^\r\n]*/ 及 您可能需要解决https://...和ftp://...等。您是否考虑过使用合适的标记器而不是正则表达式?您将只能丢弃注释标记。

在受控脚本情况下,我试图用preg replace删除不必要的注释,但我的正则表达式不正确。有人知道我的正则表达式有什么问题吗?(我有Apache/2.0.54和PHP/5.2.9

之前: 之后: 问题:使用什么正则表达式? 任何和所有的建议都会被我重视+1,因为我很快就能解开这个谜了!

试试这个正则表达式:

/(?<!http:)\/\/[^\r\n]*/


您可能需要解决
https://...
ftp://...
等。

您是否考虑过使用合适的标记器而不是正则表达式?您将只能丢弃注释标记。多行注释呢?尤其是嵌套的多行注释?这对于正则表达式来说非常重要,但对于tok来说却非常重要enizer/*这是一个/*嵌套注释*/一致地写注释,意味着没有空间做这样奇怪的事情Marc B,一个注释中的注释。然而讽刺的是,这样一个关于一致性的讲座来自一个非常无能的程序员,也就是我自己,哈哈!谢谢CDHowie,什么是标记器?你能举个例子吗要使用它?我对这个正则表达式有一个一般性的问题:它是属于PHP、Apache还是其他什么东西?标记器和正则表达式一样,只是语法不同吗?#BEAUTIFULL!!!!在注释中缺少带有注释的奇怪情况,这为更干净的代码提供了空间:您的正则表达式是第一次开箱即用!祝您好运吃周末巴特!@Sam,不客气。周末?那还需要几天,但谢谢,你今天也过得很愉快!:)
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);
/(?<!http:)\/\/[^\r\n]*/
<!-- 
// not a comment -->
/* 
// not a comment */
var s = "also // not // a // comment";