Skip to content

Instantly share code, notes, and snippets.

@tuliomonteazul
Created October 9, 2014 16:39
Show Gist options
  • Save tuliomonteazul/786f30bef77e742d28db to your computer and use it in GitHub Desktop.
Save tuliomonteazul/786f30bef77e742d28db to your computer and use it in GitHub Desktop.
Function to read a location header and get just what is after the last slash
var locationHeader = "http://www.example.com/resource/child/id123"
console.log(getIdFromLocation(locationHeader)); // should print id123
function getIdFromLocation(location) {
var extracted = /\/(\w+)$/.exec(location)
return extracted? extracted[1] : null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment