简体   繁体   中英

How to delete multiple lines with different text in between using RegEx in Notepad++?

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\$[(AZ)?]\desktop.ini

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

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:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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