0

i have a link where i need to extract some information. I am trying to figure out some kind of regex which can fetch the first portion of the string and remove it and then after the question mark remove that

need to extract the last two items from the link

http://exampke.com/9.php?type=121&sortBy=1&sortOrder=2

i am trying to detect sortby and sortorder, how should i do that, i basically tried using regex but that is only showing me the 1 & 2 changed values so i am lost how to get the

sortBy=1&sortOrder=2 from the url

2 Answers2

0

Edit, Updated

Try

    var link = "http://exampke.com/9.php?type=121&sortBy=1&sortOrder=2";
    var vals = link.split("?")[1].split(/&|=/).splice(2);
    var res = vals[0].concat("="+vals[1]).concat("&"+vals[2]+"="+vals[3]);

    var link = "http://exampke.com/9.php?type=121&sortBy=1&sortOrder=2";
    var vals = link.split("?")[1].split(/&|=/).splice(2);
    var res = vals[0].concat("=" +vals[1]).concat("&" + vals[2] + "=" + vals[3]);
    document.write(res)
guest271314
  • 1
  • 15
  • 104
  • 177
0
var url = 'http://exampke.com/9.php?type=121&sortBy=1&sortOrder=2'

var what = url.search('\\&');

var result = url.slice(what + 1, url.length);

Your result variable now contains: sortBy=1&sortOrder=2

Waxi
  • 1,641
  • 2
  • 14
  • 20