Home > Software engineering >  How to delete multiple lines with different text in between using RegEx in Notepad ?
How to delete multiple lines with different text in between using RegEx in Notepad ?

Time:10-12

What I need to do is to delete everything that ends with desktop.ini and begins with Library with varying text in between.

In my list, it looks like this:

Library\aaaa\desktop.ini
Library\bbbb\1111\desktop.ini
Library\bbbb\line-I-dont-want-to-delete
Library\cccc\222\CCCC\desktop.ini
Library\dddd\3333\D\desktop.ini

After using the Replace feature, all that should be left is:

Library\bbbb\line-I dont-want-to-delete.

I'm really terrible with RegEx, but what I need is something like this:

^Library\$[(A-Z)?]\desktop.ini

Apologies if that's all I have, but thanks in advance for helping me with this!

CodePudding user response:

You can use

Find What:    ^Library\\(?:.*\\)?desktop\.ini$\R?
Replace With: <empty>

Details:

  • ^ - start of string
  • Library\\ - Library\ string
  • (?:.*\\)? - an optional non-capturing group matching zero or more chars other than line break chars as many as possible and then a \ char
  • desktop\.ini - a desktop.ini string
  • $ - end of line
  • \R? - an optional line break char (sequence).

See the demo below:

enter image description here

  • Related