简体   繁体   English

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

[英]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_1STRING_2 (该技术称为淬火贪婪令牌 )。


You can put it in one line as well: 您也可以将它放在一行中:

 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.

相关问题 Notepad ++替换产生多行的两个字符串之间的文本并在其间保留字符串的某些部分 - Notepad++ replace text between two strings spawning multiple lines and retain some part of the string in between 如何使用Regex删除Notepad ++中两个字符串之间的文本? - How to use Regex to remove text between two strings in Notepad++? 如何在记事本中删除两个字符或字符串之间的空格 - How to remove a space between two characters or strings in notepad++ Notepad++ 和正则表达式 - 如何在两个特定字符串之间命名大小写字符串? - Notepad++ and regex - how to title case string between two particular strings? 在Notepad ++中只保留引号之间的字符串 - Keep only the strings in between quotes in Notepad++ Notepad++ 在两个竖线之间查找 50 个字符或更长的字符串 - Notepad++ Find strings 50 characters or longer between two vertical bars NOTEPAD ++ REGEX-我无法获取两个字符串之间的内容,我无法获取 - NOTEPAD++ REGEX - I can't get what's in between two strings, I don't get it 在R中的其他两个字符串之间提取一个字符串 - Extracting a string between other two strings in R 在其他两个不同字符串之间匹配字符串 - Match string between two other different strings 其他两个字符串之间的grep字符串作为分隔符 - grep string between two other strings as delimiters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM