Update replace.js

Bail out early if there are no matches, preventing an exception caused by applying an array object onto a null object.