Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

^(?!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?

like image 354
Tortenrandband Avatar asked Jun 01 '26 07:06

Tortenrandband


1 Answers

You could use this regular expression:

       Find: ^(?!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 ///),
  • They should appear in pairs in the correct order (so first start and then end)
  • They should not be nested, so after a start cannot come another start before you have an 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.

like image 53
trincot Avatar answered Jun 04 '26 16:06

trincot