繁体   English   中英

Notepad ++如果其他字符串之间存在第三个字符串,则删除两个字符串之间的文本

[英]Notepad++ Removing text between two strings if third string is present between other strings

我想删除两个字符串之间的文本,包括那些字符串,当且仅当这两个字符串之间存在第三个字符串时。 如果我可以使用Notepad ++中的替换功能来执行此操作,我会更喜欢它。

这是我需要改变的模型:

asdfnjaslfjsa
asdfjaskldfsafkldj
asdfjsadfk
STRING_1
sanjvnlamf
 fas g
gsegvrs 
STRING_2
STRING_1
asf sf gfsjasak
qweuwiouqnv
STRING_3
awi iavbfa c
anfiab
STRING_2
STRING_1
asmorancm
anib fas
STRING_2
sdabfashbdfbc  ds

改为:

asdfnjaslfjsa
asdfjaskldfsafkldj
asdfjsadfk
STRING_1
sanjvnlamf
 fas g
gsegvrs 
STRING_2
STRING_1
asmorancm
anib fas
STRING_2
sdabfashbdfbc  ds

您正在寻找的是以下结构:

STRING_1
(?:(?!STRING_2)[\s\S])*?
STRING_3
(?:(?!STRING_2)[\s\S])*?
STRING_2

仅当STRING_3存在于两者之间时,这才匹配STRING_1STRING_2 (该技术称为淬火贪婪令牌 )。


您也可以将它放在一行中:

 STRING_1(?:(?!STRING_2)[\\s\\S])*?STRING_3(?:(?!STRING_2)[\\s\\S])*?STRING_2 

请参阅regex101.com上的演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM