I need to replace & with \& when & is not at the end of the line and it is not preceded by \. I can successfully find & when it is not preceded by \, but I can not exclude those that are at the end of the line.
line 1 &
line 2
line 3 another &
line 4 & is at the middle
In above four lines, I only want to replace & with \& at line 4.
How could I do that?
Here is what I can do so far:
/\(\\\)\@<!&
Find & when it is not preceded by \. By adding negative lookahead \@!$, that is using:
/\(\\\)\@<!&\@!$
I should get those & that are not at the end of the line, but I can not.
About something like this?
Basically, replace any
&if it’s in the beginning of the line, or preceded by any character, and followed by any character.