Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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 regexp定义宏(preg#u replace)_Php_Regex_Macros_Preg Replace - Fatal编程技术网

删除多行#使用php regexp定义宏(preg#u replace)

删除多行#使用php regexp定义宏(preg#u replace),php,regex,macros,preg-replace,Php,Regex,Macros,Preg Replace,我试图用PHP regexp删除C文件中的多行宏 这是一个例子 this one should stay #define HI something is here ()d5gf \ dgkdflgj \ it ends here this one should stay #define HII something is here 2 this one should stay 输出应如下所示: this one should stay this one

我试图用PHP regexp删除C文件中的多行宏

这是一个例子

this one should stay
#define HI    something is here ()d5gf           \
dgkdflgj \
it ends here
this one should stay
        #define HII something is here 2
this one should stay
输出应如下所示:

this one should stay
this one should stay
this one should stay
我正在使用此regexp,但它无法正常工作:

preg_replace("/#define[^\n\\]+(\\\n[^\n\\])*/u", "", $input_lines);

注意:文件为UTF-8格式,这就是为什么preg_中的u会被替换。

您可以使用以下模式:

$pattern = '~#define(?=\s)(?>.*\\\\\R)*.*\R?~u';
$result = preg_replace($pattern, '', $code);