简体   繁体   中英

NP++: Clear all lines which does not contain a certain string

How to find a line in NP++, which does not contain the string (for example)

marg%233!_

I tried

.*[^(marg%233!_)].*\\r

But that seems wrong.

You want to use a negative lookahead, which will fail the whole regex if what's inside is matched:

^(?!.*marg%233!_).*\r?

and replace these matches with an empty string.

The final ? is to catch the final line of your file, and this is assuming your linebreaks are \\r . If it's not you can replace this last character with ([\\n\\r]|\\r\\n|\\n\\r) .

[^...] is a negative character class, it will match any character (and only one haracter, as [...] would) which is not contained inside the class.

There is an easy way to achieve this. You need to perform 2 steps.

  1. Go to Search menu > Find... > Select "Mark" Tab. Search for marg%233!_ . Don't forget to check "Bookmark lines" and Press "Mark All"

    ==> All Rows you want to keep got a Bookmark

  2. Go to Menu "Search - Bookmark - Remove Unmarked lines"

    ==> All lines without a bookmark are deleted.

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