Created
March 28, 2012 15:56
-
-
Save Prinzhorn/2227656 to your computer and use it in GitHub Desktop.
regex fall-throughs using a switch(true), inspired by @AvianFlu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 : ~ $ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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