Prevent _trimHash from accidentally removing $

If hasher.appendHash was not set to anything, the regular expression
being used by _trimHash would end up escaping the dollar-sign, which was
intended to be the "end of line" regular expression. This  was causing
dollar signs to be removing from hashes. The fix: Rather than always
inserting a \\ escape sequence before the prependHash and appendHash
variables, I pass them into a new private function called _escapeRegExp,
which will return an empty string if the input string is empty. This way
the resulting regex will not end up escaping the wrong thing when
appendHash is empty. In addition, if prependHash or appendHash was more
than one character long, this new escape function can handle escaping
more than one special character, so that it's future proof.