Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Multiline regex find

    Help wanted · · · – – – · · ·
    3
    9
    99
    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

      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

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

        Ekopalypse 1 Reply Last reply Reply Quote 0
        • Ekopalypse
          Ekopalypse @spiroX9000 last edited by

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

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

            @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

              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
              • Ekopalypse
                Ekopalypse last edited by

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

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

                  @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
                  • Ekopalypse
                    Ekopalypse last edited by

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

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

                      @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
                      • First post
                        Last post
                      Copyright © 2014 NodeBB Forums | Contributors