Community
    • Login

    Find All Words in Line Containing Specific String

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 3 Posters 1.3k 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.
    • Alan KilbornA
      Alan Kilborn @Mayonnaisu
      last edited by Alan Kilborn

      @Mayonnaisu

      Try:

      Find: (?-si:string@\\[|(?!\A)\G)(?s-i:(?!\\]).)*?\K(?-si:"word1")
      Search mode: Regular expression

      For background on this technique, see HERE.

      M 1 Reply Last reply Reply Quote 2
      • M
        Mayonnaisu
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • M
          Mayonnaisu @Alan Kilborn
          last edited by

          @Alan-Kilborn
          Thanks for the reply.
          I tried your regex, but it doesn’t work unfortunately.

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @Mayonnaisu
            last edited by Alan Kilborn

            @Mayonnaisu said:

            I tried your regex, but it doesn’t work unfortunately.

            On this text:

            And here is the sample text with expected matches in bold:
            string@["word1"]
            string@["word1", "word1", "word3"]
            strong@["word1", "word2", "word3"]
            string@["word1word2", "word3"]
            Could anyone please help me...
            

            A Find All in Current Document using my regex produces this:

            b96a45b3-83bb-4822-bc5f-dce4ac1dc273-image.png

            which is, I believe, exactly what you said you were looking for…

            M 1 Reply Last reply Reply Quote 3
            • M
              Mayonnaisu @Alan Kilborn
              last edited by

              @Alan-Kilborn
              Ah, my bad. You’re right. It turned out that the quotation marks I copied from the code text and plain text here are different. Hence, no match was found. Thank you so much for this!

              Alan KilbornA 1 Reply Last reply Reply Quote 3
              • Alan KilbornA
                Alan Kilborn @Mayonnaisu
                last edited by

                @Mayonnaisu

                Hmm, in your original post, you used a code block for your regex but no code block for your data. Hence you knew about code blocks; seems a pity you didn’t code-block your sample data, originally.

                Ah, maybe the explanation: You skipped the code block for the data because you wanted to put bold in the data.

                Okeee…

                1 Reply Last reply Reply Quote 2
                • guy038G
                  guy038
                  last edited by guy038

                  Hello, @mayonnaisu, @alan-kilborn and All,

                  As you’re doing a per line search, you could use the simplified generic regex, below ( also described here )

                  SEARCH (?-s)(?-i:string@|(?!\A)\G).*?\K(?-i:"word1")

                  Or, if we use the free-spacing mode, (?x), for a better lisibility :

                  SEARCH (?x-s) (?-i: string@ | (?! \A) \G ) .*? \K (?-i: "word1" )


                  To test this functional regex :

                  • Copy this text in a new tab :
                  string@["word1"]
                  string@["word1", "word1", "word3"]
                  strong@["word1", "word2", "word3"]
                  string@["word1", "word2", "word1"]
                  STRING@["word1", "word2", "word1"]
                  string@["word1word2", "word3"]
                  string@["word1", "WORD1", "word1", "word1"]
                  string@["word2", "word3", "word1"]
                  
                  • Move the caret ( cursor ) at the very beginning of the file

                  • Open the Mark dialog ( Ctrl + M )

                  • SEARCH (?x-s) (?-i: string@ | (?! \A) \G ) .*? \K (?-i: "word1" )

                  • Uncheck all box options

                  • Select the Regular expression search mode

                  • Click on the Mark All button

                  • Possibly, click on the Copy Marked Text button to paste it afterwards, wherever you want, with a Ctrl + V command

                  => This regex finds all the strings "word1", with that exact case, of each line beginning with the string string@, with that exact case too !

                  Best regards

                  guy038

                  M 1 Reply Last reply Reply Quote 1
                  • M
                    Mayonnaisu @guy038
                    last edited by

                    Hi @guy038,
                    Thank you very much for your reply. I really appreciate the additional solutions provided by you. They work like a charm!

                    1 Reply Last reply Reply Quote 1
                    • guy038G
                      guy038
                      last edited by guy038

                      Hi, @mayonnaisu and All,

                      If using the regex below, which would run a non-sensitive to case search, so an insensitive one (?i:...) :

                      SEARCH (?-s)(?i:string@|(?!\A)\G).*?\K(?i:"word1")

                      You should detect, of course, some more matches when run against my previous example !

                      BR

                      guy038

                      M 1 Reply Last reply Reply Quote 1
                      • M
                        Mayonnaisu @guy038
                        last edited by Mayonnaisu

                        @guy038

                        Awesome! Now, I have more solutions to the future problems at my disposal. Thanks!

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