Regex 正则表达式:使用行连续字符删除多个结尾
我正在寻找一个正则表达式,它将删除多行上的文本,并且只在一行没有使用特殊的“行继续”字符(反斜杠)结束时停止Regex 正则表达式:使用行连续字符删除多个结尾,regex,vim,Regex,Vim,我正在寻找一个正则表达式,它将删除多行上的文本,并且只在一行没有使用特殊的“行继续”字符(反斜杠)结束时停止 some_other_text_1 device_1 \|node1 node2 node3 \ setting1 setting2 setting3 \ setting4 setting5 some_other_text_2 device_2 \|node1 node2 node3 \ setting1 setting2 setting3 some_oth
some_other_text_1
device_1 \|node1 node2 node3 \
setting1 setting2 setting3 \
setting4 setting5
some_other_text_2
device_2 \|node1 node2 node3 \
setting1 setting2 setting3
some_other_text_3
结果输出应为:
some_other_text_1
some_other_text_2
device_2 \|node1 node2 node3 \
setting1 setting2 setting3
some_other_text_3
我使用vim将其作为查找和替换命令运行
到目前为止,我已经尝试:
%/^\s*.device_1\_.\{-}\(\\\)\@!
但是这只会运行到第一个反斜杠。这个\\\.{-}\(\\\\\)\@代码>部分仅匹配任何0+字符,尽可能少,直到第一个位置,后面不带反斜杠
some_other_text_1
device_1 \|node1 node2 node3 \
setting1 setting2 setting3 \
setting4 setting5
some_other_text_2
device_2 \|node1 node2 node3 \
setting1 setting2 setting3
some_other_text_3
您需要匹配以\
结尾的任意行数以及下一行
使用
^
-行开始
\s*
-0+空格
设备\u 1
-文字字符串
*
-行的其余部分
\(\n.\\\$\)*
-0个或多个换行符序列,然后换行符以\
\n.*
-换行符和除换行符以外的任何0+字符
///ul>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,γ-2 0 0 0 0 0,0 0 0 0 0 0 0 0 0 0 0 0 0,0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,7 7 7,0 0 0 0 0 0 0,7 7 7 7 7 7 7 7,0 0 0 0 0 0 0 0 0 0 0,7,0 0 0 0 0 0 0 0 0,7 7 7 7 7 7 7,7 7,0 0 0 0 0 0 0 0 0 0 0 0,7,7 7 7,7 7 7 7 7,2、r、h、t、t、p、s、r、e、g、e、x、1、0、c、o、m、为什么?regex101不支持Vim regex语法。@WiktorStribiżew my fault,没有很好地理解它。仅供参考:要在匹配后删除换行符,请在模式末尾添加
\n?
。