Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [Regex] Remove all but last line

    Help wanted · · · – – – · · ·
    2
    3
    1639
    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.
    • Bobby Peters222
      Bobby Peters222 last edited by

      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

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

        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 EMPTY

        OPTIONS Wrap around and Regular expression ticked

        ACTION 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 EMPTY

        OPTIONS Wrap around and Regular expression ticked

        ACTION Click on the Replace All


        If you like that solution, I’ll give you, next time, some details on these regexes !

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 1
        • Bobby Peters222
          Bobby Peters222 last edited by

          Thanks guy038 your second one worked perfectly for me. Really appreciate it.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors