@guy038 said:
Do you have an explanation ?
This is exceedingly odd. Thank you for identifying and describing it clearly. I do not have an explanation, but I think it has to be a bug (and not just a quirk of regex). Here’s why.
We can’t compare the same test in native Notepad++ search, because Mark doesn’t count or bookmark null matches. (The same with Count and Find All: in Notepad++ native search, they ignore null matches.)
However, single-step Find does identify null matches in both engines. In Notepad++ native search using Find Next, your expression (?-s)^((?!test).)*\R|\z identifies eight matches. The last is at the end of the file and shows the ^ zero length match message.
In Search++ Regex with Find, it only finds seven.
What is even more peculiar is if you switch to the ICU engine and Mark the same expressions. In ICU as in Regex, \z alone does as you would expect, bookmarking the last line and showing the message “Found 1 match (0 marked, 1 null).” ICU also does the same as Regex with (?-s)^((?!test).)*\R, marking and bookmarking seven lines, exactly as you would expect.
Adding the |\z to the end changes nothing in Regex, though you would expect to see “Found 8 matches (7 marked, 1 null)” and a bookmark on the last line. In ICU it not only doesn’t bookmark the last line, it finds and bookmarks nine matches, marking the LF, but not the CR or the rest of the line, on the lines containing test!
As far as I can tell (I might not have tested every possible combination yet), both Regex and ICU are self-consistent in that they Find and Count and Find All the same things they mark/bookmark.
Why adding |\z causes such strange behavior — in ICU even leading to new matches in the middle of the file — as yet I have no clue.