0

http://jsfiddle.net/3u4hn/1/

I have added the comments in the code for each function what I am trying to achieve here. I am using escape to match the value in url (where it will be encoded.) I am able to handle all the values except the values with decimals. For example if I have:

var s = "9%252E5|red|blue"; var itemToRemove = escape("9.5"); //escape to match the value in 's'.

As '.' can not be encoded/escaped I am not able to match the one with url, any ideas on how to deal this kind of an issue.

  • The `.` character has no special meaning in URLs, it doesn't need to be escaped. What's the problem you're having with it? Also, you shouldn't use the obsolete function `escape`, use `encodeURIComponent`. – Barmar May 16 '14 at 19:39
  • Yes, '.' can not be handled this way, but I am not sure how should I match the item with decimal as in URL it is encoded. – user3645936 May 16 '14 at 19:44
  • 1
    decodeURIComponent, then match – dandavis May 16 '14 at 19:45
  • Match in what way? Please show the code you're having trouble with? Are you trying to use it in a regular expression? You need to put `\ ` before `.` in regular expressions. – Barmar May 16 '14 at 19:46
  • the two functions are in my fiddle. – user3645936 May 16 '14 at 19:47
  • @ dandavis: tried that, but once I decode, it becomes 9.5 and now when putting back in url I cant put a encoded value again because it is a decimal again... grab an element from some other event (9.5) and search for it in url (where it is encoded) and then remove it and re-arrange the URL - this is the requirement. – user3645936 May 16 '14 at 19:51
  • +1 to dandavis's advice. You might also want to familiarize yourself with [arguments against `escape`](http://stackoverflow.com/questions/75980/best-practice-escape-or-encodeuri-encodeuricomponent) – Mike Samuel May 16 '14 at 19:52

0 Answers0