code: function (str) {
      if (caches[str]) {
        return caches[str];
      }
      
      // special regexp chars (., +, etc.)
      reg = str.replace(/[.+^$()|{}]/g, function (match, offset, s) {
        return s[offset - 1] === '\\' ? match : '\\' + match;
      });
      // ? and *
      reg = reg.replace(/[?*]/g, function (match, offset, s) {
        if (s[offset - 1] === '\\') {
          return match;
        }
        return match === '?' ? '.' : '.*';
      });
      // special regexp escapings (\d, \S, etc.)
      // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
      reg = reg.replace(/\\([dDsSwWtrnvfbB0cxu])/g, '$1');
      return caches[str] = new RegExp('^' + reg + '$');
    }
docs: make str pattern to regexp http://en.wikipedia.org/wiki/Glob_(programming)