[Regex] Remove all but last line
-
I often have to edit files that contain hundreds of lines (all urls begging with http or https) When I do this i only need the last url. It would speed my process if I could simply remove every line but the last one. Would love if this is possible, I’m not great with regex but have tried many things and have been googling for months with no luck. Would appreciate any help. Thank you
-
Hello, @bobby-teters222, and All,
It’ not clear, Bobby, if you’re speaking about :
-
The last non-empty line of your files
-
The last line, beginning by the string http: or https:
Anyway, here is the solutions for the both cases !
- To delete all text till the last non-empty line, excluded, in any scanned file, use the regex S/R :
SEARCH
(?s).*\R(?=(?-s).+)REPLACE
Leave EMPTYOPTIONS
Wrap aroundandRegular expressiontickedACTION Click on the
Replace All- To delete all text till the last line, beginning by http: or https:, excluded, in any scanned file, use the regex S/R :
SEARCH
(?s).*\R(?=(?-s)https?:.+)REPLACE
Leave EMPTYOPTIONS
Wrap aroundandRegular expressiontickedACTION Click on the
Replace All
If you like that solution, I’ll give you, next time, some details on these regexes !
Best Regards,
guy038
-
-
Thanks guy038 your second one worked perfectly for me. Really appreciate it.
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