Community
    • Login

    Regex: Copy first 5 lines from all open documents

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 3.0k Views 2 Watching
    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.
    • Vasile CarausV Offline
      Vasile Caraus
      last edited by

      hi, I want to copy just the first 5 lines from all open documents, for this I made the regex below:

      \A(?:.*\n){5} or

      \A^.*(?:\R.*){5} or

      ^(?:.*\R){5}

      But none of the variants is good because the operation is redundant, keeps repeated on every 5 lines. So I need strictly the first 5 lines !

      cand anyone help me?

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • Scott SumnerS Offline
        Scott Sumner @Vasile Caraus
        last edited by

        @Vasile-Caraus

        Your best option might be to do a replacement rather than a find–I’m not sure how you’d easily “copy” the results otherwise.

        I’d try:

        Find what zone: (?-s)((?:.*?\R){5})(?s).*
        Replace with zone: \1
        Search mode: Reg Exp (obviously!)
        Action: Press Replace All in All Open Docs button
        Post-replace actions: Go to all of the tabs individually, select-all, copy, Undo (the Replace All)…then paste the clipboard contents wherever you are accumulating the results

        Probably not what you are looking for, though…

        1 Reply Last reply Reply Quote 0
        • Vasile CarausV Offline
          Vasile Caraus
          last edited by

          I believe the best option to search and find, which I tested again and works very good, is this one:

          \A^.*(?:\R.*){5}

          I am using grepWIn to search and find and copy the first 5 lines from a lot of files :)

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

            Hi, @vasile-caraus, @Scott-sumner and All,

            Indeed, in that matter, N++ totally fails to solve this simple goal :-(( And this, for two main reasons :

            • Firstly, because the N++ regex engine does not handle properly, backward assertions ( as \A , \<, \b before a word,… )

            • Secondly, because the results, in the Find result windows, display a single line , even if a multi-lines amount of text had been matched !


            For instance, as a work-around, with the François-R Boyer regex engine, and N++ v6.9.0, I used, successively, the following 5 regexes :

            • (?-s)\A(.*\R){0}\K.*\R , which, correctly, match the first line of any opened file

            • (?-s)\A(.*\R){1}\K.*\R , which, correctly, match the second line of any opened file

            • (?-s)\A(.*\R){2}\K.*\R , which, correctly, match the third line of any opened file

            • (?-s)\A(.*\R){3}\K.*\R , which, correctly, match the fourth line of any opened file

            • (?-s)\A(.*\R){4}\K.*\R , which, correctly, match the fifth line of any opened file

            After 5 clicks, on the Find All in All Opened Documents button, I, then, copied these 5 search results in a new tab.

            Finally, after a classical sort, depending on the file name and the number of the line matched, I could get the 5 first lines of all my opened files ! Quite boring !


            Here, Vasile, it should be interesting to use, instead, a simple Lua or Python script, for nice and immediate results ! Of course, some external tools, as you said, can realize this work, quite well, too !

            Best Regards,

            guy038

            You may look this alternative solution, in the last part of this post :

            https://notepad-plus-plus.org/community/topic/15058/regex-remove-particular-words-from-tags-in-several-text-pages/11

            1 Reply Last reply Reply Quote 1

            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
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors