Add the /g global flag, so all occourances of the '#' get replaced with ...

...the encoded %23' value. Closes #1961
Not sure how I got this so wrong in the first place! Yes, single quotes should be omitted, and leading / added. I will correct, and make a new PR. Thanks.