Skip to content

Instantly share code, notes, and snippets.

@lxe
Created April 25, 2013 19:03
Show Gist options
  • Save lxe/5462224 to your computer and use it in GitHub Desktop.
Save lxe/5462224 to your computer and use it in GitHub Desktop.
var r = new RegExp(
// ^ - not the following...
// \/\? - slash and a question mark
// + - 1 or more of them
'[^/?]+'
// Followed by (but don't capture this!)...
// ?= - don't capture!
// ^ - not the following...
// / - a slash
// * - 0 or more of those
// $ - followed by the end of line
+ '(?=[^/]+$)'
);
console.log('http://a.com/b/c/this_is_what_we_want?q=poop'.match(r).toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment