Community
    • Login

    [Regex] Remove all but last line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 2.1k 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.
    • Bobby Peters222B
      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
      • guy038G
        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 Peters222B
          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
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors