Community
    • Login

    REGEX again: How can I select/mark this 3 works on a different lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    20 Posts 2 Posters 8.0k Views 2 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.
    • Vasile CarausV Offline
      Vasile Caraus
      last edited by Vasile Caraus

      hello guy38, I wasn’t here, sorry.
      So, I test all your new regex. First, the long regex, replace by #$0 works very good.

      The little problem are the next 3 SUCCESSIVELY regex. One by one. After Search and Replace with \1, I get the successful message “6 occurrences has were replaced.”

      The problem is that, in fact, nothing has changed…is like nothing happen…

      The last of the 3 successively regex (?-s)^#.*(Recente|Coments|Tags).*, after replace with \1, removes the # sign witch I had put with the first long regex

      1 Reply Last reply Reply Quote 0
      • Vasile CarausV Offline
        Vasile Caraus
        last edited by

        Oh, WORKS ! I use another example. So, excuse-me. All your regex works just fine guy38. You practically move all 3 words to the beginning of lines.

        Thanks a lot

        1 Reply Last reply Reply Quote 0
        • Vasile CarausV Offline
          Vasile Caraus
          last edited by Vasile Caraus

          and, I return to my old problem. Now with your help, I manage to take all 3 words to the start of the lines. The question was, how can I mark/delete something before or after those 3 words. For example:

          text bla Commens
          text bla bla Tags

          Recente
          Coments
          Tags

          text bla Recente
          text bla bla Tags

          So, you see that the words “Recente, Coments and Tags” are repeating. So, I manage to resolve my first problem: HOW TO DELETE EVERYTHING BEFORE THOSE 3 words on the 3 successively lines, included those 3 lines:

          Search
          ((?s)((^.*)^Recente|^Coments|^Tags))(.*$)
          Replace by:
          Leave empty

          1 Reply Last reply Reply Quote 0
          • Vasile CarausV Offline
            Vasile Caraus
            last edited by

            Now, to delete everything after those 3 words (and 3 lines) included those 3 lines

            Search:
            ^.*(?s)^Recente|^Coments|^Tags.*[\s\S]
            Replace by:
            leave empty

            1 Reply Last reply Reply Quote 0
            • Vasile CarausV Offline
              Vasile Caraus
              last edited by

              so, you see my friend, where I wanted to get. The single problem was that all that 3 words, were somewhere in the middle of the lines, and I didn’t know how to select those SUCCESSIVELY lines.

              thanks a lot.

              But If you know another 2 regex to do directly this, for deleting before and after, without adding the 3 words at the beggining at the lines, please let me know.

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

                Vasile,

                I’m just back on our forum and, after reading your post, where you said :

                The problem is that, in fact, nothing has changed…is like nothing happen…

                I quickly guessed why it did NOT work :-) Ah ! Again, I forgot to add this VERY IMPORTANT fact :

                If your pattern regex contains one or more look-behinds AND/OR any \K form, you must, EXCLUSIVELY use the Replace All button to perform a global replacement.

                DON’T use the Replace button, for a step by step replacement : it does NOTHING !!

                So, for performing, correctly, my three previous regexes :

                (?-s)^#(?:.+\R){2}\K.*(Recente|Coments|Tags).*

                (?-s)^#.+\R\K.*(Recente|Coments|Tags).*

                (?-s)^#.*(Recente|Coments|Tags).*

                with replacement \1

                • Move the caret, before the text to change

                • Perform the three S/R, in that order, by clicking, EXCLUSIVELY, on the Replace All button ( Not the Replace button !! )

                It should be OK

                Of course, don’t forget to delete the extra # character, at the end

                Cheers,

                guy038

                So, I updated my previous post !

                1 Reply Last reply Reply Quote 0
                • Vasile CarausV Offline
                  Vasile Caraus
                  last edited by

                  WORKS !!!

                  1 Reply Last reply Reply Quote 0
                  • Vasile CarausV Offline
                    Vasile Caraus
                    last edited by

                    A different nice regex looks like this. First check . match newline

                    Search:
                    .*\n([ \t]+Recente\s+Coments\s+Tags).*
                    REPLACE By:
                    $1 or \1

                    Don’t forget to check . match newline

                    This will select all that 3 words, even if are delimitaded by tab or spaces. And will delete the rest of document.
                    But how can I use this regex, to remove everything only before those 3 words, and another regex to remove only after those 3 words?

                    1 Reply Last reply Reply Quote 0
                    • Vasile CarausV Offline
                      Vasile Caraus
                      last edited by

                      or, without check . match newline

                      Search:
                      (?s).*\n([ \t]+Recente\s+Coments\s+Tags).*(.*$)
                      REPLACE By:
                      $1 or \1

                      1 Reply Last reply Reply Quote 0
                      • Vasile CarausV Offline
                        Vasile Caraus
                        last edited by

                        hello, I find the solutions:

                        So, to delete everything before those 3 words, included the 3 lines with the words:

                        Search:
                        (?s).*\n([ \t]+Recente\s+Coments\s+Tags)
                        Replace By:
                        Leave Empty

                        Delete everything after those 3 words included the 3 lines with the words:
                        Search:
                        (?s)([ \t]+Recente\s+Coments\s+Tags)(.*$)
                        Replace by:
                        $1

                        1 Reply Last reply Reply Quote 0

                        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