Get URL Parameters formula

The “get url parameters” custom formula in Apps Script helps in extracting specific parameters from a URL. It can be useful in cases where you need to extract a parameter value from a URL string and use it for further processing.

Here’s an example of how to use this custom formula:

function GETURLPARAM(url, name) {
  var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
  var results = regex.exec(url);
  if (!results) return null;
  if (!results[2]) return '';
  return decodeURIComponent(results[2].replace(/\+/g, " "));

The custom formula accepts two parameters: the URL string and the name of the parameter you want to extract.

Let’s say you have a URL like this: If you want to extract the value of the lang parameter, you can use the following formula: =GETURLPARAM(A1,"lang"), where A1 is the cell containing the URL. This will return the value “en”.

You can also use this formula in combination with other formulas to perform more complex operations, such as filtering a list based on a parameter value extracted from a URL.

Overall, the “get url parameters” custom formula can be a handy tool in extracting and using specific values from a URL string.