Created
October 17, 2011 06:07
-
-
Save mattryall/1292030 to your computer and use it in GitHub Desktop.
Regex fall-throughs using if/else, inspired by simplicity and clarity
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
[17:05] node-test$ node switch.js for the fail | |
fail | |
[17:05] node-test$ node switch.js for the lose | |
lose | |
[17:05] node-test$ node switch.js bleep blah | |
blah | |
[17:05] node-test$ node switch.js for the win | |
win |
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(' '); | |
if (m = s.match(/fail/)) { | |
console.log('fail'); | |
} else if (m = s.match(/for the (\S+)/)) { | |
console.log(m[1]); | |
} else if (m = s.match(/blah/)) { | |
console.log('blah'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment