Skip to content

Instantly share code, notes, and snippets.

@jdx
Last active April 30, 2016 01:57
Show Gist options
  • Save jdx/8d5171b511a0f01bf467 to your computer and use it in GitHub Desktop.
Save jdx/8d5171b511a0f01bf467 to your computer and use it in GitHub Desktop.
JS ES6 Destructurin' with Regex
// node 6
let msg = "Merge pull request #222 from heroku/api-key-warning-whoami show warning if HEROKU_API_KEY is set"
let [, pr, branch, message] = msg.match(/Merge pull request (#\d+) from ([\S]+) (.*)/)
// node 5
let msg = "Merge pull request #222 from heroku/api-key-warning-whoami show warning if HEROKU_API_KEY is set"
let matches = msg.match(/Merge pull request (#\d+) from ([\S]+) (.*)/)
let pr = matches[1]
let branch = matches[2]
let messages = matches[3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment