code: function attemptReplace(token, pattern, replacement, callback) {
      var result = null;
      
      if((typeof pattern == 'string') && token.substr(0 - pattern.length) == pattern)
          result = token.replace(new RegExp(pattern + '$'), replacement);
      else if((pattern instanceof RegExp) && token.match(pattern))
          result = token.replace(pattern, replacement);
          
      if(result && callback)
          return callback(result);
      else
          return result;
  }
docs: replace a pattern in a word. if a replacement occurs an optional callback can be called to post-process the result. if no match is made NULL is returned.