Because with this regex vim can choose any point for starting match for your regular expression. Obviously it chooses the point where first concat matches (i.e. does not have //
or :
). These things are normally done by using either
\v^%(%(\/\/|\:)@!.)*\w$
(removed first concat and the branch itself, changed .*
to %(%(\/\/|\:)@!.)*
; replaced collection with equivalent \w
; added anchor pointing to the start of line): if you need to match the whole line. Or negative look-behind if you need to match only the last character. You can also just add anchor to the first concat of your variant (you should remove trailing .*
from the first concat as it is useless, and the branch symbol for the same reason).
Note: I have no idea why your regex worked for comments. It does not work with comments the way you need it in all cases I checked.