Community
    • Login

    Remove last word of each line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 7 Posters 2.0k 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.
    • Andrea FerroA
      Andrea Ferro
      last edited by Andrea Ferro

      Hi everyone. I would like to remove the last word of each line. It has to do with many song names ending with a portion of the youtube URL that always contains 11 letters. I’m trying to get the song title clean, without the URL.

      From this:
      PJS Nebulas (Promotional Edit) DN_9ZbWRUWU
      Jilo First Times Valley (E​-​Ger​ä​t Remix) tOjgku6iNhY
      Sachi Kobayashi Still Remember SK3jAqN5Myw

      To This:
      PJS Nebulas (Promotional Edit)
      Jilo First Times Valley (E​-​Ger​ä​t Remix)
      Sachi Kobayashi Still Remember

      How can I do?

      Lycan ThropeL 1 Reply Last reply Reply Quote 0
      • Lycan ThropeL
        Lycan Thrope @Andrea Ferro
        last edited by Lycan Thrope

        @Andrea-Ferro ,
        Start here:
        https://npp-user-manual.org/docs/searching/#regular-expressions
        Figure, you need to find the last 11 characters of a line, and replace them with nothing.

        On the off chance you actually did try, this is what I came up with while you were reading it. :)

        Find what: (.*(?=(?<=)[\w+]{11}))(.*)
        Replace with: $1
        Search Mode: Regular Expression
        Dot Matches Newline = NOT CHECKED

        This will leave a space behind the last letter. If you want that gone too, I suspect you’ll have to up the {11} to {12}, but if there is no space there, you’ll chop off letters.

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

          Hello, @andrea-ferro, @lycan-thrope and All,

          Why not this simple one :

          SEARCH (?-s).{12}$

          REPLACE Leave EMPTY

          Regular expression checked

          Possibly Wrap around checked

          One click only on the Replace All button

          Best Regards

          guy038

          Alan KilbornA Bahaa0013B Lycan ThropeL 3 Replies Last reply Reply Quote 3
          • Alan KilbornA
            Alan Kilborn @guy038
            last edited by Alan Kilborn

            @guy038 said in Remove last word of each line:

            SEARCH (?-s).{12}$

            While @guy038’s suggestion appears to remove 12 characters when only 11 characters were wanted for removal, he’s also eliminating the space character that comes before the final 11, which seems fine to me.

            1 Reply Last reply Reply Quote 2
            • Bahaa0013B
              Bahaa0013 @guy038
              last edited by

              @guy038
              Hi sir!
              you helped me a lot :)
              Do you know a way to convert email and pass from:

              email: example@domain.com
              password: 123123
              

              to:

              example@domain.com:123123
              
              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @Bahaa0013
                last edited by

                @Bahaa-Eddin-ツ ,

                You already asked that. Be patient, and keep the discussion there.

                Your new question has nothing to do with “remove last word of each line”, and shouldn’t be asked in this discussion.

                1 Reply Last reply Reply Quote 2
                • Lycan ThropeL
                  Lycan Thrope @guy038
                  last edited by

                  @guy038 ,
                  Cleaner and simpler. Mine broke when I tried my suggestion of changing the {11} to {12}. Not sure why, but it did.

                  Terry RT 1 Reply Last reply Reply Quote 0
                  • Terry RT
                    Terry R @Lycan Thrope
                    last edited by Terry R

                    @Lycan-Thrope said in Remove last word of each line:

                    Mine broke when I tried my suggestion of changing the {11} to {12}. Not sure why, but it did.

                    That’s because the class you used [\w+] had 2 issues. First you stated it should be a word character, thus one of the alphanumeric characters plus underscore, see boost documentation. So as it does not include a space, but the space and 11 characters were what you wanted to select (in your adjusted version with {12}), it wasn’t going to select any of the lines. You also could have replaced the + with a space character and you would have selected the lines.

                    Second issue was that the + you added did not mean as many of the \w as possible, but actually just a + character. So if you replaced one of those spaces before the 11 \w characters with a + character your regex would have worked on that 1 line with the quantifier of {12}.

                    Possibly, had you entered your regex into regex101.com the description may have alerted you to the mistake. So although it worked (on 11 characters) the premise behind it was unfortunately wrong.

                    But, and I fully intend to end on a positive note, it was a useful exercise for you. I too was once in your shoes. Sometimes you learn more by the mistakes you make. I often used regex101.com to find out the description, it really can be useful. Don’t forget though that as it uses a similar (but not the same) regex engine there can sometimes be differences.

                    Terry

                    Lycan ThropeL 1 Reply Last reply Reply Quote 3
                    • Lycan ThropeL
                      Lycan Thrope @Terry R
                      last edited by Lycan Thrope

                      @Terry-R ,
                      Thanks, and you’re right, I learn more, by trying. I had started to use regex101.com, but for the reason you mention, some of the boost stuff throws an error in it. I think I may have used a bad character or something when it threw the error, so I went to the NPP S/R box to try out what I had. Thanks for the reasoning behind the failure. I had tried a \h, but that failed also, so…at least I have another tool in the box to understand the next time I try. :)

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