Community
    • Login

    Remove any content starting from a and ending at b

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 4 Posters 1.0k 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.
    • Auditormadness9A
      Auditormadness9
      last edited by

      I am trying to regex search like this (http).*(",), but instead of matching multiple areas that are between an http string and a ", string, it instead selects the ENTIRE area from the first ever occurence of http up until the last occurence of ", which is NOT what I want, I instead want it to find all the instances of areas between those two strings.

      Any help for this will be gladly appreciated!^^

      PeterJonesP Neil SchipperN 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Auditormadness9
        last edited by

        @Auditormadness9 ,

        The sub-expression .* will try to capture as much as possible, which is why your expression is grabbing from the first http to the last ",. To make it non-greedy, in order to capture the least amount possible (and thus the first http to the first ",), use .*? – the ? modifies the * to be non-greedy.

        • https://npp-user-manual.org/docs/searching/#multiplying-operators
        1 Reply Last reply Reply Quote 0
        • Neil SchipperN
          Neil Schipper @Auditormadness9
          last edited by

          @Auditormadness9

          the ENTIRE area from the first ever occurence of http up until the last occurence of ",

          Sounds like it’s matching multiple lines. To stop this, ensure that in Find window, Search mode, “. matches newline” is not checked. This will confine matches to (parts of) each line.

          Then, either your orig (greedy) or non-greedy as per Peter’s suggestion, will give the hoped for result.

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

            @Neil-Schipper said in Remove any content starting from a and ending at b:

            ensure that in Find window, Search mode, “. matches newline” is not checked. This will confine matches to (parts of) each line.

            Careful with a statement such as that, as I can easily write a regular expression that will have multiple lines in a single match even when that checkbox is checked.

            It only disallows the . used in the regex to match line-ending characters; it does nothing to prevent other constructs from matching across line boundaries.

            Neil SchipperN 1 Reply Last reply Reply Quote 0
            • Neil SchipperN
              Neil Schipper @Alan Kilborn
              last edited by

              @Alan-Kilborn Of course, but we are discussing the actual search string @Auditormadness9 tried, which won’t span lines with the “dot matches” deselected as I suggested.

              Alan KilbornA 2 Replies Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @Neil Schipper
                last edited by

                @Neil-Schipper

                Correct, but other people come along and read this stuff and perhaps would grab onto a statement like “. matches newline…will confine matches to parts of each line”.

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

                  @Neil-Schipper

                  And anyway, for all we know, the OP does want to span lines with his matches. Who’s to say, because he (OP) didn’t.

                  Neil SchipperN 1 Reply Last reply Reply Quote 0
                  • Neil SchipperN
                    Neil Schipper @Alan Kilborn
                    last edited by

                    @Alan-Kilborn

                    for all we know, the OP does want to span lines with his matches

                    OP wrote:

                    but instead of matching multiple areas that are between an http string and a "

                    which sounds to me like he wants the greedy form but acting per line.

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

                      @Neil-Schipper

                      It’s inconclusive, unless OP comes back for more help.
                      We’ve seen it many times.

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