Community
    • Login

    Extract the lines greater than

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 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.
    • zarate peteryZ
      zarate petery
      last edited by

      friends how can i select the lines that have movies greater than 14

      user = 8732560 | domainId = 5674567 | points = 22.21 | N° movies = 13
      user = 13567799 | domainId = 8879095 | points = 0.01 | N° movies = 1
      user = 7688898 | domainId = 454679 | points = | N° movies = 24
      user = 8743210 | domainId = 5633556 | points = 1 | N° movies = 17

      to

      user = 7688898 | domainId = 454679 | points = | N° movies = 24
      user = 8743210 | domainId = 5633556 | points = 1 | N° movies = 17

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

        Hello @zarate-petery and All,

        Easy with regular expressions !

        As you don’t say anything about the upper limit of the movies numbers, I suppose that 999 was the maximum !

        This leads to that regex S/R, with select all contents, including their line-breaks, of lines with a movies number greater than 14

        SEARCH (?-s)^.+(?:[1-9]\d\d|1[5-9]|[2-9]\d)\R?

        Notes : This regex is almost obvious ! A few points :

        • The (?-s) in-line modifier, at beginning of pattern ensures that the regex dot symbol represents a single standard character and not a line-break character

        • The (?:....|.....|.....) is the syntax of a non-capturing group of several alternatives

          • The 1st alternative looks for a three-digit number

          • The 2nd alternative looks for a two-digit number between 15 and 19

          • The 3rd alternative looks for a two-digit number greater than 19

        • The \R? represents any line-break character(s) of current scanned line. The ? quantifier, meaning {0,1} have been added just in case that the last line does not have any line ending

        Best regards

        guy038

        Alan KilbornA 1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @guy038
          last edited by

          @guy038 @zarate-petery

          A couple of things:

          1. When I try @guy038’s regex on the OP’s data, I get hits on all four lines. The OP wanted only the 3rd and 4th lines to be hit.

          2. OP says “how can i select the lines?”. To that I say “What are you wanting to do with them?” Notepad++ currently contains no go way to select (as in “selected text”) data in this fashion, so if you want to copy only the data matching the criterion somewhere else, you have to turn to other mechanisms.

          So back to the regex. I think it was @guy038’s desire to handle the “last line does not have any line ending” condition (probably a “late addition” to a finished solution?) that tripped up the regex. I’d suggest these variants, all of which seem to work:

          (?-s)^.+(?:[1-9]\d\d|1[5-9]|[2-9]\d)\R <— requires a line-ending on last line to match the last line

          or

          (?-s)^.+(?:[1-9]\d\d|1[5-9]|[2-9]\d)$\R? <— adds a $ to anchor what comes before to line-ending

          or

          (?-s)^.+(?:[1-9]\d\d|1[5-9]|[2-9]\d)(?:\R|\z) <— use \z for special end-of-file / last-line handling

          Alan KilbornA 1 Reply Last reply Reply Quote 3
          • Alan KilbornA
            Alan Kilborn @Alan Kilborn
            last edited by Alan Kilborn

            @Alan-Kilborn said in Extract the lines greater than:

            Notepad++ currently contains no go way…

            Ach. Was supposed to be “Notepad++ currently contains no good way…”

            But @zarate-petery , if you really need a way to copy out the matched data, let us know, and we’ll provide one.

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

              Hi, @zarate-petery and All,

              Oh, My God ! I was totally wrong in many ways :-((

              • Firstly @zarate-petery said :

              user = 8732560 | domainId = 5674567 | points = 22.21 | N° movies = 13
              user = 13567799 | domainId = 8879095 | points = 0.01 | N° movies = 1
              user = 7688898 | domainId = 454679 | points = | N° movies = 24
              user = 8743210 | domainId = 5633556 | points = 1 | N° movies = 17

              to

              user = 7688898 | domainId = 454679 | points = | N° movies = 24
              user = 8743210 | domainId = 5633556 | points = 1 | N° movies = 17

              And I thought that the OP wanted to select the entire lines with last number greater than 14. Not at all ! May be, the OP just wants to delete lines with last number under 15 !


              • Secondly, I tested my search regex against the text, below, and, obviously, as it contains only one number per line, my regex wrongly worked nice !
              Test 1
              Test 2
              Test 3
              ....
              ....
              Test 149
              Test 150
              

              So, thanks to Alan, the right regex is one of his 3 solutions !

              However, I think it would be better to add the \x20 syntax, right after the .+ part. Indeed, by default, the first part of the pattern ^.+\x20 would match exactly what we want to ! No need for any backtracking ;-))

              For instance, the Alan’s 2nd solution would be changed as (?-s)^.+\x20(?:[1-9]\d\d|1[5-9]|[2-9]\d)$\R?


              Now, if the OP prefers that solution, here is a regex S/R, which deletes any line ending with a number smaller than 15 :

              SEARCH (?-s)^.+\x20(?:1[0-4]|\d)$\R?

              REPLACE Leave EMPTY

              Best Regards

              guy038

              Alan KilbornA 1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @guy038
                last edited by

                @guy038 said in Extract the lines greater than:

                And I thought that the OP wanted to select the entire lines with last number greater than 14.

                Yes, you thought that because that’s what the OP said. :-)

                May be, the OP just wants to delete lines with last number under 15 !

                I don’t know about that.
                I’ve already queried the OP on what his end goal is.
                Probably best to wait for that answer, if it ever comes.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors