Match everything but exclude words - notepad ++

Input:

start
some
T1
random
T2
text
T3
end

      

it should look like this:

start
T1
T2
T3
end

      

I tried to use

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

      

to combine everything between the beginning and the end

and exclude T1 T2 T3 with:

^(?!T\d)

Is it possible to combine them into a single regex that can be inserted into notepad ++ for people unfamiliar with writing code to do it in a few passes?

+3


source to share


1 answer


You can use this regex:

    Find: ^(?!T\d|start).*\R(?=(^(?!start$).*\R)*end$)


    Replace: (empty) matches newlines: None
    .

Click "Replace All"



These assumptions are made:

  • start

    And delimiters end

    must be the only text on their lines (not ---start

    or start ///

    ),
  • They must appear in pairs in the correct order (first start

    and then end

    )
  • They don't have to be nested, so start

    there can't be another one start

    after you have it end

    .

Looking ahead makes this a rather inefficient regex, as on every match it needs to check the text again, which follows until the next one end

.

+1


source







All Articles