Multiline regex find
-
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. -
Sorry for the “italic” look, I tried the edit but it only works 180s after the post.
-
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. -
@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.
-
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 thistransport.*\n.*owner
and thistransport.*\R.*owner
works normally. -
@Alan-Kilborn said in Multiline regex find:
I would put a (?-s) on the front of that, to get:
(?-s)transport.\R.?ownerAlternatively: 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. -
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
-
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? -
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 beenUntick 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.