+1 vote

I have a simple text file with two words in it. The words are on different, but adjacent lines as below:

test
this

However, if I enter 'test this' (without apostrophes) into the 'Containing Text' search bar, and I select Multi-Line Regex, FLP 8 fails to find the text. Restricting the search for just one word or the other works fine, but I thought the purpose of Multi-Line Regex was to search for content on adjacent lines...

Am I doing something wrong?

by (245 points)

1 Answer

0 votes

Text on adjacent lines is not the same as being space separated. A multi-line regex works by spanning lines, so in your case you'd need to search for the expression (or something similar):

 test\r\nthis

This is the intended functionality.

Normal Regex vs Multi-line Regex

The underlying regex engine that performs the match comparison is exactly the same for both expression types, the difference is that the normal regex engine matches lines on a line-by-line basis. That is, a line is pulled from the source, tested against the regular expression, and kept if a match is found. Each line is searched like that, so the match is independent of any other line.

Multi-line regex works by reading the whole file (or at least a large chunk of lines if the file is very large) and then matching the expression over the whole text. This is most often useful when a search expression might be split over several lines.

Since a multi-line expression is searched over a much larger chunk of text it will normally be slower than the normal regex. Therefore if the search term (e.g. email address pattern) is not expected to span line boundaries it is recommended that you use the normal regular expression option.

by (29.6k points)
I think I see..  But to help me, and possibly others (since there is not much documentation about Multi-Line Regex), can you share a classic case where Multi-Line Regex is a better or simpler way to find content than normal Regex?  That may (or may not) be the same as this question:  when does Multi-Line Regex find content that normal Regex does not?
I've updated the answer, does that help?
Yes, it helps a bit, but I'm still not understanding.

How might a search expression be "split over several lines" (as you describe) if not split by a carriage return between adjacent lines? I'm not following.

Perhaps my confusion arises because I'm thinking in the context of text in a text file.

Thanks!
Imagine that you were searching over a log file where you might want to search for two concurrent log entries. The CR LF tells you that they're separate entries. Or you want to find a line of source code that's within 5 lines of another line. I can see how a text document might be different because the concept of a line doesn't really apply, ie you'd work in sentences and paragraphs. In that case a Boolean NEAR expression might make more sense.
...