简体   繁体   English

匹配所有内容但排除单词 - notepad ++

[英]Match everything between but exclude words - notepad++

Input: 输入:

start
some
T1
random
T2
text
T3
end

should result in: 应该导致:

start
T1
T2
T3
end

I tried using 我试过用

>(?<=start)[\S\s]*?(?=end)

to match everything between start and end 匹配开始和结束之间的所有内容

and exclude T1 T2 T3 with: 并排除T1 T2 T3:

^(?!T\\d)

Is it possible to combine them into a single regex that can be pasted into notepad++ for people not familiar with writing code to do it in several passes? 是否有可能将它们组合成一个可以粘贴到记事本++中的正则表达式,以便那些不熟悉编写代码的人在几次传递中执行它?

You could use this regular expression: 你可以使用这个正则表达式:

Find: ^(?!T\\d|start).*\\R(?=(^(?!start$).*\\R)*end$) 查找: ^(?!T\\d|start).*\\R(?=(^(?!start$).*\\R)*end$)
Replace: (empty) 替换:(空)
. matches newlines: No 匹配换行:

Click "Replace All" 点击“全部替换”

These assumptions are made: 这些假设是:

  • The start and end delimiters should each be the only text on their lines (so not ---start or start /// ), startend分隔符应该是它们行上唯一的文本(所以不是---startstart /// ),
  • They should appear in pairs in the correct order (so first start and then end ) 它们应该以正确的顺序成对出现(所以首先start然后end
  • They should not be nested, so after a start cannot come another start before you have an end . 他们不应该被嵌套,所以后一start不能到另一个start你有一个前end

The look-ahead makes this a rather inefficient regular expression, as with each match it needs to check again the text that follows until the next end . 前瞻使得这是一个相当低效的正则表达式,因为每次匹配需要再次检查后续文本直到下一个end

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

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