Community
    • Login

    Find All Words in Line Containing Specific String

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 3 Posters 3.6k Views 1 Watching
    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 Offline
      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 Offline
        Mayonnaisu
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • M Offline
          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 Offline
            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 Offline
              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 Offline
                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 Offline
                  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 Offline
                    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 Offline
                      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 Offline
                        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

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors