Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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
Regex 正则表达式-替换具有相同空行数的多行_Regex_Notepad++ - Fatal编程技术网

Regex 正则表达式-替换具有相同空行数的多行

Regex 正则表达式-替换具有相同空行数的多行,regex,notepad++,Regex,Notepad++,是否可以使用正则表达式替换具有相同空行数的多行 在上下文中,我需要能够更改以下内容: 01 /*------------------------------------ 02 Some history stuff goes here 03 Some history stuff goes here 04 Some history stuff goes here 05 Some history stuff goes here 06 Some history stu

是否可以使用正则表达式替换具有相同空行数的多行

在上下文中,我需要能够更改以下内容:

01    /*------------------------------------
02    Some history stuff goes here
03    Some history stuff goes here
04    Some history stuff goes here
05    Some history stuff goes here
06    Some history stuff goes here
07    --------------------------------------*/
08    int main void()
09    {
10       printf("Hello, World!");
11
12       return 0;
13    }
01    
02    
03    
04    
05    
06    
07    
08    int main void()
09    {
10       printf("Hello, World!");
11
12       return 0;
13    }
具体如下:

01    /*------------------------------------
02    Some history stuff goes here
03    Some history stuff goes here
04    Some history stuff goes here
05    Some history stuff goes here
06    Some history stuff goes here
07    --------------------------------------*/
08    int main void()
09    {
10       printf("Hello, World!");
11
12       return 0;
13    }
01    
02    
03    
04    
05    
06    
07    
08    int main void()
09    {
10       printf("Hello, World!");
11
12       return 0;
13    }
现在我只有以下正则表达式模式,但它仅用一行替换第01-07行:

\/\*.*?\*\/
(. matches newline checked)

如果有帮助的话,我会使用记事本++的“在文件中查找”功能,因为我需要在文件夹中的多个文件中进行查找。

因为您使用的是
notpad++
我假设您在windows上。您可能需要使用power shell来实现这一点。 首先逐行读取文件,找到

然后,当该行以
/*
开头,以
*/
结尾时,执行一些逻辑,源代码


此perl one liner完成以下工作:

perl -ne 'if (/\/\*/ .. /\*\//) {print "\n"} else {print}' file > output
在windows下,将单引号更改为双引号

perl -ne "if (/\/\*/ .. /\*\//) {print \"\n\"} else {print}" file > output

@sweaver2112“ff”是“following”的快捷方式,你检查过了吗?@STIKO谢谢,但我不想删除“空行”我想用相同数量的“空行”替换“block comments”我想你需要一些脚本命令来完成这项工作,regex不提供“匹配的行数”替换中的变量。@sweaver2112对如何开始有任何建议吗?