code: function strictReplace(str, pairs, multiline) {
    var index;
    var fromIndex = 0;
  
    pairs.some(function (pair) {
      var toReplace = pair[0];
      var replaceWith = pair[1];
  
      index = str.indexOf(toReplace, fromIndex);
      if (index === -1) {
        return true;
      }
  
      var lhs = str.substr(0, index);
      var rhs = str.substr(index + toReplace.length);
  
      if (multiline) {
        lhs = trimSpaceAndPunctuation(lhs);
        rhs = trimSpaceAndPunctuation(rhs);
      }
  
      str = lhs + replaceWith + rhs;
  
      fromIndex = index + replaceWith.length;
  
      return false;
    });
  
    return str;
  }
docs: Replace while increasing indexFrom If multiline is true - eat all spaces and punctuation around diffed objects - it will keep things look nice.