• Login
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.
  • A
    Auditormadness9
    last edited by Oct 6, 2021, 1:22 PM

    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!^^

    P N 2 Replies Last reply Oct 6, 2021, 1:41 PM Reply Quote 0
    • P
      PeterJones @Auditormadness9
      last edited by Oct 6, 2021, 1:41 PM

      @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
      • N
        Neil Schipper @Auditormadness9
        last edited by Oct 6, 2021, 8:36 PM

        @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.

        A 1 Reply Last reply Oct 6, 2021, 8:43 PM Reply Quote 0
        • A
          Alan Kilborn @Neil Schipper
          last edited by Alan Kilborn Oct 6, 2021, 8:44 PM Oct 6, 2021, 8:43 PM

          @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.

          N 1 Reply Last reply Oct 6, 2021, 8:50 PM Reply Quote 0
          • N
            Neil Schipper @Alan Kilborn
            last edited by Oct 6, 2021, 8:50 PM

            @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.

            A 2 Replies Last reply Oct 6, 2021, 9:09 PM Reply Quote 0
            • A
              Alan Kilborn @Neil Schipper
              last edited by Oct 6, 2021, 9:09 PM

              @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
              • A
                Alan Kilborn @Neil Schipper
                last edited by Oct 6, 2021, 9:13 PM

                @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.

                N 1 Reply Last reply Oct 6, 2021, 9:19 PM Reply Quote 0
                • N
                  Neil Schipper @Alan Kilborn
                  last edited by Oct 6, 2021, 9:19 PM

                  @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.

                  A 1 Reply Last reply Oct 6, 2021, 10:31 PM Reply Quote 0
                  • A
                    Alan Kilborn @Neil Schipper
                    last edited by Oct 6, 2021, 10:31 PM

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