How to query lines with "string2" inside files with "string1"

Here’s a modification of @I-d-as’s workaround that selects across >1 line:

/string1.*(.*\n)*.*string2|string2.*(.*\n)*.*string1/

It will select from the first string1 to the last string2 (and vice-versa), so you won’t see individual results for any occurrences of string2 between them.

I believe this modification using “lookahead/lookbehind assertions” would fulfill @AMGMNPLK’s entire request, but it freezes Obsidian:

/(?<=string1.*(.*\n)*.*)string2|string2(?=.*(.*\n)*.*string1)/

I guess it checks too big a number of possibilities. I’m trying to find a way to make it work.

2 Likes