• Login
Community
  • Login

Match lines that don't contain any of the specified strings.

Scheduled Pinned Locked Moved General Discussion
regex
4 Posts 3 Posters 5.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J
    Jadian Radiator
    last edited by Oct 15, 2020, 2:58 AM

    I already know how to match lines not containing a singular string from this .
    However I can’t figure out how to make it work on multiple sub strings all at the same time.
    This is the list of strings I’m needing to regex search&replace through.
    I need to match everything except the lines beginning with either a hyphen, or the phrase “Mining Level:”
    This is a screenshot of the regex search patterns I’ve tried.
    Though some of the ones with “.+” have “. matches new line” turned on.

    A 1 Reply Last reply Oct 15, 2020, 1:40 PM Reply Quote 0
    • T
      Terry R
      last edited by Terry R Oct 15, 2020, 4:27 AM Oct 15, 2020, 4:25 AM

      @Jadian-Radiator said in Match lines that don't contain any of the specified strings.:

      match lines not containing a singular string

      You might need to be more concise with what you need to do as you firstly state I need to match lines not containing (suggesting removing the whole line), but later you refer to the search and replace function suggesting ONLY portions of lines need editing/removing.

      I will show you a method of removing complete lines which don’t have specific strings in them. This uses the “Mark” function. As an example I copied your post and used “Mark” along with “bookmark lines” to mark those lines to KEEP.
      096a3cd6-e086-4ffb-955f-9532d7291e33-image.png
      As you will see I used 3 strings separated by the | character which is the “alternation” meta character. It allows for multiple searches to be carried out simultaneously. Although my strings were plain text you could use regular expressions, provided the search mode is set to “regular expression”.

      By running this multiple times (which I think you may need to do if the link you provided shows ALL strings to be searched) you can mark additional lines, until you have completed all the marking operations. Then you can remove “unmarked” lines by using the function “Remove Unmarked Lines” under Search, Bookmark.

      Additional to that we have you need to exclude lines starting with a hyphen or a particular string. As my Mark idea is actually the reverse of finding lines NOT containing strings, perhaps you could also do that with this additional request. Mark those using ^-|mining level.

      Hopefully this will help, otherwise you may need to elaborate.

      Terry

      J 1 Reply Last reply Oct 15, 2020, 4:47 PM Reply Quote 4
      • A
        Alan Kilborn @Jadian Radiator
        last edited by Oct 15, 2020, 1:40 PM

        @Jadian-Radiator

        I already know how to match lines not containing a singular string from this.
        I can’t figure out how to make it work on multiple sub strings all at the same time.

        So the basis of your situation is: (?!badword).)*

        Have you tried something like this?: (?!(badword1)|(badword2).)*

        1 Reply Last reply Reply Quote 2
        • J
          Jadian Radiator @Terry R
          last edited by Oct 15, 2020, 4:47 PM

          @Terry-R
          Thankyou, “bookmarking” got it to work for me.

          1 Reply Last reply Reply Quote 2
          • T Terry R referenced this topic on Feb 21, 2025, 7:08 PM
          2 out of 4
          • First post
            2/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors