$string should be used when checking for previous character

Fixes #1941
Merge pull request #1974 from Dragooon/release-2.1

$string should be used when checking for previous character