• Login
Community
  • Login

Search and select lines containing all keywords in notepad++

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 3.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.
  • M
    maria nita
    last edited by Feb 19, 2019, 5:47 PM

    Hi,
    I am looking for a regular expression or any option… that allows me to search and select lines from notepad++, that contain all of the keywords.

    Eg.
    The CAT and the DOG are friends
    The CAT is named Purr.
    The DOG is named Bark.
    It is raining CATs and DOGs.

    I need to select lines 1 and 4.

    Please help

    A 1 Reply Last reply Feb 19, 2019, 6:16 PM Reply Quote 1
    • A
      Alan Kilborn @maria nita
      last edited by Feb 19, 2019, 6:16 PM

      @maria-nita

      Do you know how to use google?

      If not, then: https://stackoverflow.com/questions/4389644/regex-to-match-string-containing-two-names-in-any-order

      M 1 Reply Last reply Feb 19, 2019, 6:49 PM Reply Quote 3
      • M
        maria nita @Alan Kilborn
        last edited by Feb 19, 2019, 6:49 PM

        @Alan-Kilborn
        Thanks for the link

        1 Reply Last reply Reply Quote 1
        • G
          guy038
          last edited by guy038 Feb 19, 2019, 8:36 PM Feb 19, 2019, 8:33 PM

          Hello, @alan-kilborn, @maria-nita and All,

          Alan, the first answer of this stackoverflow’s topic is really the best one ;-))

          Indeed ! At first sight, although that, in OP text , word CAT always precedes the word DOG, I thought about the search regex, below :

          ^.*(CAT).*(DOG).*|^.*(?2).*(?1).*

          However, the syntax ^(?=.*CAT)(?=.*DOG).* is really more elegant !


          We can generalize to any number of words and, also, add conditions which should not occur ;-)) . For instance, the following regex would match all lines, with their line-breaks, which :

          • Contain the 3 expressions WORD_1 AND WORD_2 AND WORD_5

          • Does NOT contain the 2 expressions WORD_4 OR WORD_6

          (?-s)^(?=.*WORD_1)(?=.*WORD_2)(?=.*WORD_5)(?!.*WORD_4)(?!.*WORD_6).*\R

          So, it matches the lines 5, 12 and 14, only, in the text :

          This line   1  contains   WORD_1  WORD_2
          This line   2  contains   WORD_1  WORD_3  WORD_5
          This line   3  contains   WORD_3  WORD_5  WORD_4
          This line   4  contains   WORD_1  WORD_5
          This line   5  contains   WORD_5  WORD_2  WORD_1
          This line   6  contains   WORD_2  WORD_1  WORD_6  WORD_5
          This line   7  contains   WORD_4  WORD_1  WORD_5
          This line   8  contains   WORD_2
          This line   9  contains   WORD_5  WORD_2  WORD_4  WORD_7  WORD_1
          This line  10  contains   WORD_1  WORD_6  WORD_2
          This line  11  contains   WORD_4  WORD_2  WORD_1, WORD_5  WORD_6
          This line  12  contains   WORD_7  WORD_2  WORD_5  WORD_1
          This line  13  contains   WORD_6  WORD_2  WORD_1  WORD_5
          This line  14  contains   WORD_1  WORD_5  WORD_8  WORD_2  WORD_3
          

          Best Regards,

          guy038

          1 Reply Last reply Reply Quote 3
          4 out of 4
          • First post
            4/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors