$string should be used when checking for previous character

Fixes #1941