Skip to content

Instantly share code, notes, and snippets.

@ingo-eichhorst
Last active May 24, 2016 08:05
Show Gist options
  • Save ingo-eichhorst/0ef0ccd4642ac72e032aaf1947fc096d to your computer and use it in GitHub Desktop.
Save ingo-eichhorst/0ef0ccd4642ac72e032aaf1947fc096d to your computer and use it in GitHub Desktop.
A regex (regular expression) to parse the HTTP header X-Callback
// http://progrium.com/blog/2012/11/26/x-callback-header-an-evented-web-building-block/
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec
// input
var input = <http://example.com/callback/>; method="post"; secret="123"; secret2="123"
// regex deliver url and method:
// <(http:\/\/\S*)>.*method="(\w*)"
var matches = /<(http:\/\/\S*)>.*method="(\w*)"/.exec(input);
console.log(matches[1]); // http://example.com/callback/
console.log(matches[2]); // post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment