Created
October 9, 2014 16:39
-
-
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
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 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