index.js
function regret(name, input){
  var matchers, res = null, re, matches, matcher;
  if(typeof name.exec === 'function'){
    matchers = Object.keys(regret.matchers).filter(function(m){
      return name.test(m);
    }).map(function(m){
      return regret.matchers[m];
    });
  }
  else {
    matchers = regret.matchers[name] ? [regret.matchers[name]] : [];
  }

  if(matchers.length === 0){
    return undefined;
  }

  while(matchers.length > 0){
    matcher = matchers.shift();
    matches = matcher.pattern.exec(input);

    if(!matches){
      continue;
    }
    res = {};

    // pop off the input string
    matches.shift();
    matches.map(function(p, i){
      res[matcher.captures[i]] = p;
    });
    break;
  }
  return res;
}
function regret(name, input){
  var matchers, res = null, re, matches, matcher;
  if(typeof name.exec === 'function'){
    matchers = Object.keys(regret.matchers).filter(function(m){
      return name.test(m);
    }).map(function(m){
      return regret.matchers[m];
    });
  }
  else {
    matchers = regret.matchers[name] ? [regret.matchers[name]] : [];
  }

  if(matchers.length === 0){
    return undefined;
  }

  while(matchers.length > 0){
    matcher = matchers.shift();
    matches = matcher.pattern.exec(input);

    if(!matches){
      continue;
    }
    res = {};

    // pop off the input string
    matches.shift();
    matches.map(function(p, i){
      res[matcher.captures[i]] = p;
    });
    break;
  }
  return res;
}
function regret ( name , input ) { var matchers , res = null , re , matches , matcher ; if ( typeof name . exec === 'function' ) { matchers = Object . keys ( regret . matchers ) . filter ( function ( m ) { return name . test ( m ) ; } ) . map ( function ( m ) { return regret . matchers [ m ] ; } ) ; } else { matchers = regret . matchers [ name ] ? [ regret . matchers [ name ] ] : [ ] ; } if ( matchers . length === 0 ) { return undefined ; } while ( matchers . length > 0 ) { matcher = matchers . shift ( ) ; matches = matcher . pattern . exec ( input ) ; if ( ! matches ) { continue ; } res = { } ; // pop off the input string matches . shift ( ) ; matches . map ( function ( p , i ) { res [ matcher . captures [ i ] ] = p ; } ) ; break ; } return res ; }
Don't let the regex party get out of control.
Don t let the regex party get out of control .