1

Here is my URI.

/v1/securemessages/members/{mbruid}?folder=Inbox

I want to split this URI using javascript and pass the value of mbruid to a stored procedure.

Here is my script.

function getQueryParam(encUrl,pathverIndex){

    var url,reqURIParam;
    url=decodeURIComponent(encUrl);
    pathVarArr = url.split('/');
    reqURIParam =pathVarArr[pathverIndex];
    return reqURIParam;
}

mbruid = getQueryParam(tags["encURL"],4);

The problem is that I am getting {mbruid}?folder=Inbox instead of {mbruid}. Please help me modify my script so the only desired variable is returned.

Black Sheep
  • 6,604
  • 7
  • 30
  • 51
temesgen
  • 161
  • 1
  • 2
  • 8

3 Answers3

0

A few ways to do this but here's one specific to your url:

Working Example

var x = url.split('?')[0].split('/').splice(-1);
omarjmh
  • 13,632
  • 6
  • 34
  • 42
0

You can try this

var uri = "/v1/securemessages/members/{mbruid}?folder=Inbox",
   data = uri.match(/[^/]*(?=\?)/)[0];

Explanation as follows

[^/]*(?=\?)

Regular expression visualization

Debuggex Demo

Redu
  • 25,060
  • 6
  • 56
  • 76
0

One way would to do something like:

var foo = url.split('/');
var test = foo[4].split('?')
test[0] // {bruid}
skipZero
  • 162
  • 10