删除除多线模式以外的所有内容,其中结束定义为第一行之后的 1 行
Delete everything except multiline pattern, in which the end is defined as 1 line after the first line
我想删除所有与模式不匹配的内容
我试过的:
我对这个正则表达式模式进行正斜杠搜索:
\d\+_.*\n.*
匹配两对线:
A
50
Y
Not allowed
According to registry coding
3_Tumour_ID ### match
Tumour identification ### match
A
50
Y
Not allowed
According to registry coding
4_Day_DoB ### match
Day of birth ### match
F
2
然后我尝试删除除这些匹配之外的所有内容:
:v//d
我明白了:
3_Tumour_ID
4_Day_DoB
但我期待的是:
3_Tumour_ID
Tumour identification
4_Day_DoB
Day of birth
这是正确的,因为它保留了所有匹配的行,而不仅仅是每个匹配项的第一行。
我要匹配的第二行(在我希望匹配的每对行中)完全匹配的前提是它紧接在每一对中的第一行之后。
您不能使用 :v//del comd
来完成它。因为您的搜索模式包含新行,所以 :g, :v
将进行基于行的处理。因此 Tumour...
和 Day of...
行将由 :v
再次处理,最后删除。
您可以尝试的是:
qaq (to clear "a register)
:g//norm! "A2Y (this copy all matched lines into register a)
ggVG"ap
注意:我用2Y
是因为你的pattern中有一个\n
,也就是说,你的匹配结果总是两行。
我想删除所有与模式不匹配的内容
我试过的:
我对这个正则表达式模式进行正斜杠搜索:
\d\+_.*\n.*
匹配两对线:
A
50
Y
Not allowed
According to registry coding
3_Tumour_ID ### match
Tumour identification ### match
A
50
Y
Not allowed
According to registry coding
4_Day_DoB ### match
Day of birth ### match
F
2
然后我尝试删除除这些匹配之外的所有内容:
:v//d
我明白了:
3_Tumour_ID
4_Day_DoB
但我期待的是:
3_Tumour_ID
Tumour identification
4_Day_DoB
Day of birth
这是正确的,因为它保留了所有匹配的行,而不仅仅是每个匹配项的第一行。
我要匹配的第二行(在我希望匹配的每对行中)完全匹配的前提是它紧接在每一对中的第一行之后。
您不能使用 :v//del comd
来完成它。因为您的搜索模式包含新行,所以 :g, :v
将进行基于行的处理。因此 Tumour...
和 Day of...
行将由 :v
再次处理,最后删除。
您可以尝试的是:
qaq (to clear "a register)
:g//norm! "A2Y (this copy all matched lines into register a)
ggVG"ap
注意:我用2Y
是因为你的pattern中有一个\n
,也就是说,你的匹配结果总是两行。