How to get variable out of URL with executeScript_Sandbox

Dear community ,

I would like to get a variable from an URL.
As far as I know executeScript supports Java Sript.

As a beginner, I would like to know how to use it in combination with getQueryVariable().
My Url looks like this:

nameofthewebsite.com/PHP?ref_id=12345

I need the number 12345.

Thank you in advance!

To slice of parts of a string, use the “substring” JS function. The internal var ${!URL} contains the current URL.

executeScript_Sandbox | var s = ${!URL}; s = s.substring(s.lastIndexOf("=") + 1, s.length); return s; | number

Test macro:

{
  "Name": "slice",
  "CreationDate": "2020-5-9",
  "Commands": [
    {
      "Command": "store",
      "Target": "nameofthewebsite.com/PHP?ref_id=12345",
      "Value": "myurl"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var s = ${myurl};  s = s.substring(s.lastIndexOf(\"=\") + 1,      s.length); return s; ",
      "Value": "n"
    },
    {
      "Command": "echo",
      "Target": "${n}",
      "Value": "lime"
    }
  ]
}