Possible Duplicate:
Get query string values in JavaScript
I “had” this pattern but it didn’t quite give me what I need, though it worked.
var regex = new RegExp('\\b' + data.keyword + '(=[^&]*)?(&|$)',"gi");
But the following regular expressions “is” what I need but i can’t seem to get it to work within the regex obj:
/&dyanmicTxtHere(\=[^&])?(?=&|$)|^dyanmicTxtHere(\=[^&])?(&|$)/
I tried: This is NOT working –
var regex = new RegExp('&' + data.keyword + '(=[^&]*)?|^' + data.keyword + '(=[^&]*)?&?',"gi");
I can’t figure out why. So the above regex should strip out my passed param (and vlaue)(data.keyword), and deal with the ? and & wherever that param sits in the url. It
So, what would this match?
http://www.someurl.com?Keyword=foo
http://www.someurl.com?up=down&Keyword=foo
http://www.somurl.com?up=down&keyword=foo&left=right
etc… so, if I passed in “Keyword” as my dynamic param, then it would remove it and its associated value.
Obviously what follows is not a regular expression; but it should, I think, fulfil your requirements. It takes advantage of the requirements of name-value pairs in a GET query-string, and uses simple string, and some array, manipulation to examine the various (if any) name-value pairs from the passed URL:
JS Fiddle demo.