Community
    • Login

    Can I find missing lines with regular expression?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 2 Posters 2.0k Views 1 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.
    • Robin CruiseR Offline
      Robin Cruise
      last edited by

      hello, and happy new year everyone. I have a question. Is it possible to find missing lines with regular expression?

      So, I have a lot of lines with numbers from 1 to 2000. There are some id’s extracted from a ranking php script. And I want to find out if I missed a number.

      In this example I write only 8 lines, with different numbers. 2 numbers are missing 5 and 9.

      1
      2
      3
      4
      6
      7
      8
      10

      My desire output result [5,9]. So, to do this, I believe I should use a regex that will count the lines of notepad and the numbers that I have at each line. Then compare. And if there is a number missing, the cursor should stop at the line before that is missing. Something like this.

      Can anyone help me?

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

        Hello, @robin-cruise, and All,

        Happy Near Year to you and to any N++ user, too !

        Regarding your problem, if all lines of your file begin with a line number, here is my solution :

        • Copy/paste your file contents in a new tab

        • At the end of this new tab, after your contents, add 2,000 blank lines, with multiple line-break and/or several Ctrl-C/Ctrl-V actions

        • Now, move again to the first blank line, after your contents

        • With the column editor ( ALT + C ), insert increasing numbers to all the remaining blank lines ( Check the leading zeros option if necessary and verify that the final number is equal to the total of your contents ( 2000 )

        • On the entire file, perform a classical sort ( option Edit > Line Operations > Sort lines Lexicographically Ascending )

        • Now, either :

          • Move to any missing line on every occurrence of the search regex ^(\d+)\R(?!\1)

          • Execute the regex S/R, below, to see the complete list of missing lines :

        SEARCH : (?-s)^(?:(\d+)\R\1.*\R)+

        REPLACE Leave EMPTY

        Hope that these two work-around will helps you ;-))

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 2
        • Robin CruiseR Offline
          Robin Cruise
          last edited by

          hello, @guy038 . I follow all your steps. I have numbers from 5,000 to 6,090. Edit > Line Operations > Sort lines Lexicographically Ascending. Ok. Now, If I search ^(\d+)\R(?!\1) it’s ok, jumps over the duplicate numbers or over those lines that are not in order numbers. Works great. Beautiful.

          But the second regex, does not working. Please check this out. https://snag.gy/VC7LKk.jpg

          1 Reply Last reply Reply Quote 0
          • Robin CruiseR Offline
            Robin Cruise
            last edited by

            sorry, both regex are working fine. Thank you very much.

            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