substitute `\\` and `\$` idempotently