code: function regexFromString(string) {
    var r = /::|\*\*|:[a-zA-Z_]+|\*/g;
    var match;
    var regexString = '^';
    var previousIndex = 0;
    var regexKeys = [];
    var starKey = 0;
    while ((match = r.exec(string)) !== null) {
      var matched = match[0];
      var index = match.index;
      regexString += escapeRegex(string.slice(previousIndex, index));
      previousIndex = index;
      if (matched === '**') {
        regexString += '\\*\\*';
        previousIndex += 2;
      } else if (matched === '::') {
        regexString += '::';
        previousIndex += 2;
      } else if (matched === '*') {
        regexString += '(.*)';
        regexKeys.push(starKey);
        previousIndex += 1;
        starKey++;
      } else {  // :foo
        regexString += '([^/]+)';
        regexKeys.push(matched.slice(1));
        previousIndex += matched.length;
      }
    }
    regexString += escapeRegex(string.slice(previousIndex)) + '$';
    var regex = new RegExp(regexString);
    regex.keys = regexKeys;
    return regex;
  }
docs: Convert a String to a RegExp, escaping everything. Make * stand for anything and :foo be a named non-slash placeholder. ** is a star, :: is a colon.