Remove last word of each line
-
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 SK3jAqN5MywTo This:
PJS Nebulas (Promotional Edit)
Jilo First Times Valley (E-Gerät Remix)
Sachi Kobayashi Still RememberHow can I do?
-
@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.
-
Hello, @andrea-ferro, @lycan-thrope and All,
Why not this simple one :
SEARCH
(?-s).{12}$
REPLACE
Leave EMPTY
Regular expression
checkedPossibly
Wrap around
checkedOne click only on the
Replace All
buttonBest Regards
guy038
-
@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.
-
@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
-
@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.
-
@guy038 ,
Cleaner and simpler. Mine broke when I tried my suggestion of changing the{11}
to{12}
. Not sure why, but it did. -
@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
-
@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. :)