A problem with zero-width matches

Suppose you have a buffer like this:
```
a
b

c
d

e
```
Then type `M-x phi-replace RET $ RET ! RET`, and the buffer is updated as follows:
```
a!
b
!
c!
d
!
e
```
Some positions are missed out, presumably where the position N and the position N+1 both match the pattern.