• Login
Community
  • Login

Multiline regex find

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 3 Posters 1.5k 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.
  • S
    spiroX9000
    last edited by Oct 19, 2020, 10:20 AM

    Hi,
    I am trying to match “WORD-A anything-new line-anything WORD-B”.
    In the example below I am trying to match “transport.*$\n^.*owner”:

    {transport_bridge_vlan,
    [{owner,trm},{removable,true}],
    {untaggedBridgePorts,[]},
    {userLabel,[]},

    However, no matter what syntax I use for the regexp I can’t match “new line” (in any case not just one above). “Extended” option works but in that case regex “." doesn’t work. When enabling “show all characters” line end shows LF, so I am assuming \n should cover it, but nothing matches. I’ve tried:
    \n \N{newline} \r \R \x0A “dot” (with “matches newline” option included).
    Also if I copy from the end of the line to the beginning of the next and paste that into the search window, the search window is blank but it does match. That is under “normal” search.
    $ works for end of line as in "transport.
    $” and ^ works for the beginning as in “^.*owner”.
    This https://regex101.com/ shows my syntax as correct. Am I using regex in Npp wrong or is something broken in mine? I am using 64bit 7.5.9 version.
    Thank you.

    1 Reply Last reply Reply Quote 0
    • S
      spiroX9000
      last edited by Oct 19, 2020, 10:27 AM

      Sorry for the “italic” look, I tried the edit but it only works 180s after the post.

      E 1 Reply Last reply Oct 19, 2020, 10:49 AM Reply Quote 0
      • E
        Ekopalypse @spiroX9000
        last edited by Oct 19, 2020, 10:49 AM

        @spiroX9000

        I am trying to match “WORD-A anything-new line-anything WORD-B”.

        given that I would say transport.*\R.*?owner should do it.
        If your caret is below the text you try to find make sure you have checked
        word wrap otherwise make sure your caret is at the first position in the document.

        A 1 Reply Last reply Oct 19, 2020, 12:03 PM Reply Quote 0
        • A
          Alan Kilborn @Ekopalypse
          last edited by Oct 19, 2020, 12:03 PM

          @Ekopalypse said in Multiline regex find:

          transport.\R.?owner

          I would put a (?-s) on the front of that, to get:

          (?-s)transport.*\R.*?owner

          Alternatively: Tick the . matches newline box.

          1 Reply Last reply Reply Quote 0
          • S
            spiroX9000
            last edited by Oct 19, 2020, 12:25 PM

            Thanks for the help, I have tried both of those but it didn’t work. I finally managed to do it, it looks like it was an issue with the installation. I’ve had it installed through Microsoft Store. After i uninstalled it, and downloaded latest 7.9 version and then installed normally it worked.
            Now this transport.*\n.*owner and this transport.*\R.*owner works normally.

            1 Reply Last reply Reply Quote 1
            • E
              Ekopalypse
              last edited by Oct 19, 2020, 12:54 PM

              @Alan-Kilborn said in Multiline regex find:

              I would put a (?-s) on the front of that, to get:
              (?-s)transport.\R.?owner

              Alternatively: Tick the . matches newline box.

              I’m confused, doesn’t (?-s) mean, dot does NOT match newlines?
              Even as this is the default I see the advantage to being explicit about it
              but I don’t understand the alternative.

              A 1 Reply Last reply Oct 19, 2020, 1:01 PM Reply Quote 1
              • A
                Alan Kilborn @Ekopalypse
                last edited by Oct 19, 2020, 1:01 PM

                @Ekopalypse

                doesn’t (?-s) mean, dot does NOT match newlines?

                Yes, but only with ..
                You were explicitly matching a line-ending by using \R.

                The only thing my addition of (?-s) gives is that yours (without it) could potentially (deps on state of checkbox) match, fully all of this text:

                transportblahblah
                blahblahownerblah
                blah
                ...possibly a lot of lines here...and a lot of owner
                blah
                blah
                ...the next line is the last owner
                owner
                

                And mine, with the (?-s) will match only this part of the same text:

                transportblahblah
                blahblahowner
                
                1 Reply Last reply Reply Quote 0
                • E
                  Ekopalypse
                  last edited by Oct 19, 2020, 1:09 PM

                  @Alan-Kilborn

                  that was the part I understood

                  Even as this is the default I see the advantage to being explicit about it

                  but Alternatively: Tick the . matches newline box. confused me as this means (?s), correct?

                  A 1 Reply Last reply Oct 19, 2020, 1:16 PM Reply Quote 1
                  • A
                    Alan Kilborn @Ekopalypse
                    last edited by Alan Kilborn Oct 19, 2020, 1:17 PM Oct 19, 2020, 1:16 PM

                    @Ekopalypse

                    Alternatively: Tick the . matches newline box. confused me as this means (?s), correct?

                    That’s what we in the business call an “Alan screw-up”.
                    Yes, of course that should have been Untick the . matches newline box
                    It’s what I meant, but there was a disruption on the way from my brain to my fingertips.
                    Apologies for the confusion.

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