1

I working on the Query String and used the other separator or demilitator. Now I interest for delete.

I read the question Delete parameter and I use the script's write of LukePH.

    function removeParameter(url, parameter)
{
  var urlparts= url.split('?');

  if (urlparts.length>=2)
  {
      var urlBase=urlparts.shift(); //get first part, and remove from array
      var queryString=urlparts.join("?"); //join it back up

      var prefix = encodeURIComponent(parameter)+'=';
      var pars = queryString.split(/[&;]/g);
      for (var i= pars.length; i-->0;)               //reverse iteration as may be destructive
          if (pars[i].lastIndexOf(prefix, 0)!==-1)   //idiom for string.startsWith
              pars.splice(i, 1);
      url = urlBase+'?'+pars.join('&');
  }
  return url;
}

The separator is:

            Separator


javascript              Mako           

  =                       %24+
  &                       +%23+

In this script there is

var pars = queryString.split(/[&;]/g);

I want change the sentence for use split on the separator +%23+

var pars = queryString.split(/[+%23+;]/g);

This not function because contains too many values.

How to change the regex for locate to string?

Community
  • 1
  • 1
Mirko Cianfarani
  • 2,023
  • 1
  • 23
  • 39

1 Answers1

1

Square brackets define a character class, as in a set of potential matches, so it makes no sense to put two of the same character in a character class. What you need to do is escape your special characters...

var pars = queryString.split(/\+%23\+;/g);
Billy Moon
  • 57,113
  • 24
  • 136
  • 237