[英]Notepad++ Removing text between two strings if third string is present between other strings
I would like to remove the text between two strings, including those strings, if and only if a third string is present between those two strings. 我想删除两个字符串之间的文本,包括那些字符串,当且仅当这两个字符串之间存在第三个字符串时。 I would greatly prefer it if I could use the replace functionality in Notepad++ to do this.
如果我可以使用Notepad ++中的替换功能来执行此操作,我会更喜欢它。
Here's a mock-up of what I need altered: 这是我需要改变的模型:
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
Changed to this: 改为:
asdfnjaslfjsa
asdfjaskldfsafkldj
asdfjsadfk
STRING_1
sanjvnlamf
fas g
gsegvrs
STRING_2
STRING_1
asmorancm
anib fas
STRING_2
sdabfashbdfbc ds
What you are looking for can be achieved with the following construct: 您正在寻找的是以下结构:
STRING_1
(?:(?!STRING_2)[\s\S])*?
STRING_3
(?:(?!STRING_2)[\s\S])*?
STRING_2
This matches STRING_1
to STRING_2
only if STRING_3
is present in between (the technique is called a tempered greedy token ). 仅当
STRING_3
存在于两者之间时,这才匹配STRING_1
到STRING_2
(该技术称为淬火贪婪令牌 )。
STRING_1(?:(?!STRING_2)[\\s\\S])*?STRING_3(?:(?!STRING_2)[\\s\\S])*?STRING_2
See a demo on regex101.com . 请参阅regex101.com上的演示 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.