Skip to content

Instantly share code, notes, and snippets.

@Prinzhorn
Created March 28, 2012 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prinzhorn/2227656 to your computer and use it in GitHub Desktop.
Save Prinzhorn/2227656 to your computer and use it in GitHub Desktop.
regex fall-throughs using a switch(true), inspired by @AvianFlu
substack : ~ $ node switch.js bleep blah
blah
substack : ~ $ node switch.js for the lose
lose
substack : ~ $ node switch.js for the win
win
substack : ~ $ node switch.js for the fail
fail
substack : ~ $
var m, s = process.argv.slice(2).join(' ');
switch (false) {
case !(m = s.match(/fail/)) :
console.log('fail');
break;
case !(m = s.match(/for the (\S+)/)) :
console.log(m[1]);
break;
case !(m = s.match(/blah/)) :
console.log('blah');
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment