Created
February 24, 2013 20:16
-
-
Save therealplato/5025421 to your computer and use it in GitHub Desktop.
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 url = 'https://dominion.isotropic.org/gamelog/201302/24/game-20130224-103117-6c8c2cb8.html'; | |
var regex = /^https?:\/\/dominion\.isotropic\.org\/gamelog\/\d*\/\d\d\/game\-(\d*)\-([^.]*)\.html$/; | |
var result = url.match(regex); | |
//console.log(result); | |
if(result){ | |
console.log('date: '+result[1]); | |
console.log('id: '+result[2]); | |
}; | |
/* Annotated | |
/^ //Begin regex, anchor to beginning of line | |
https?:\/\/dominion\.isotropic\.org | |
// s? means, match zero or one s | |
\/gamelog\/\d*\/\d\d | |
//forward slashes, dots, dash must be escaped. \d=digit | |
\/game\-(\d*)\-([^.]*) | |
// capture group 1 is game date | |
// capture group 2 (from - to next .) is game id or something? | |
\.html | |
$/ //End regex, anchor to EOL | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment