dist/watchman.js
function pathToRegExp(path) {
    if (path instanceof RegExp) {
      return {
        keys: [],
        regexp: path
      };
    }
    if (path instanceof Array) {
      path = '(' + path.join('|') + ')';
    }

    var rtn = {
      keys: [],
      regexp: null
    };

    rtn.regexp = new RegExp((isHashRouter(path) ? '' : '^') + path.replace(/([\/\(]+):/g, '(?:').replace(/\(\?:(\w+)((\(.*?\))*)/g, function (_, key, optional) {
      rtn.keys.push(key);
      var match = null;
      if (optional) {
        match = optional.replace(/\(|\)/g, '');
      } else {
        match = '/?([^/]+)';
      }
      return '(?:' + match + '?)';
    })
    // fix double closing brackets, are there any better cases?
    // make a commit and send us a pull request. XD
    .replace('))', ')').replace(/\*/g, '(.*)') + '((#.+)?)$', 'i');

    return rtn;
  }
function pathToRegExp(path) {
    if (path instanceof RegExp) {
      return {
        keys: [],
        regexp: path
      };
    }
    if (path instanceof Array) {
      path = '(' + path.join('|') + ')';
    }

    var rtn = {
      keys: [],
      regexp: null
    };

    rtn.regexp = new RegExp((isHashRouter(path) ? '' : '^') + path.replace(/([\/\(]+):/g, '(?:').replace(/\(\?:(\w+)((\(.*?\))*)/g, function (_, key, optional) {
      rtn.keys.push(key);
      var match = null;
      if (optional) {
        match = optional.replace(/\(|\)/g, '');
      } else {
        match = '/?([^/]+)';
      }
      return '(?:' + match + '?)';
    })
    // fix double closing brackets, are there any better cases?
    // make a commit and send us a pull request. XD
    .replace('))', ')').replace(/\*/g, '(.*)') + '((#.+)?)$', 'i');

    return rtn;
  }
function pathToRegExp ( path ) { if ( path instanceof RegExp ) { return { keys : [ ] , regexp : path } ; } if ( path instanceof Array ) { path = '(' + path . join ( '|' ) + ')' ; } var rtn = { keys : [ ] , regexp : null } ; rtn . regexp = new RegExp ( ( isHashRouter ( path ) ? '' : '^' ) + path . replace ( / ([\/\(]+): / g , '(?:' ) . replace ( / \(\?:(\w+)((\(.*?\))*) / g , function ( _ , key , optional ) { rtn . keys . push ( key ) ; var match = null ; if ( optional ) { match = optional . replace ( / \(|\) / g , '' ) ; } else { match = '/?([^/]+)' ; } return '(?:' + match + '?)' ; } ) // fix double closing brackets, are there any better cases? // make a commit and send us a pull request. XD . replace ( '))' , ')' ) . replace ( / \* / g , '(.*)' ) + '((#.+)?)$' , 'i' ) ; return rtn ; }
Convert the path string to a RegExp object
@param  {String} path path
@return {RegExp}      RegExp object
Convert the path string to a RegExp object