Skip to content

Instantly share code, notes, and snippets.

@therealplato
Created February 24, 2013 20:16
Show Gist options
  • Save therealplato/5025421 to your computer and use it in GitHub Desktop.
Save therealplato/5025421 to your computer and use it in GitHub Desktop.
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