Describe the bug
Backreferences are supposed to match the text that the nominated group matched. But once .* and \n are involved in the group, the regular expression engine can match different text in the backreference, allowing the backreference to kind of expand the .* a second time.
To Reproduce
Detailed steps to reproduce the behavior:
vim --clean (or gvim --clean, etc.)foo
bar
barnaby
baz
bar\nbarnaby\n. (It’s like it searched for \(^.*\)\n\1.*\n instead.)Expected behavior
There should be no matches: in the case that did match, \1 is bar\n, which is different from “barn\n”.
(\(^.*$\)\n\1\n does not exhibit this bug.)
Environment (please complete the following information):
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
can confirm and the 'regexpengine' setting does not seem to make a difference
As well, (^.*\n)\1 does not match duplicated lines at the end of the file.
It gets weirder, the pattern ^(.*\n)\1xyz matches neither
foo
foo
xyz
nor
foo
foobar
xyz
yet the pattern ^(.*\n)\1fyz matches both of these.
It looks like the bug has nothing to do with .*, just with backreferences to groups ending in a newline: @chris-morgan's example still works if you search for ^\(bar\n\)\1 instead of ^\(.*\n\)\1. Similarly, replacing .* by foo in my previous comment does not change the results.