0

Would like to take document.URL, find the string with curly brackets, remove the curly brackets, and show just the string that was inside the curly brackets. However, it seems that document.URL or window.location.href convert the curly brackets to hexidecimal values (%7B & %7D) and then I can't match against the actual {string}. Any help would be appreciated.

  var txt = document.URL; // My URL is something like http://site.com/somepage&value0={string}
  var re1='.*?';    // Non-greedy match on filler
  var re2='(\\{.*?\\})';    // Curly Braces 1

  var p = new RegExp(re1+re2,["i"]);
  var m = p.exec(txt);

  if (m != null)
  {
      var cbraces1=m[1];
      document.write(cbraces1.replace("{","").replace("}",""));
  }
Usman
  • 41
  • 2
  • 6

2 Answers2

2

Use decodeURI(document.URL) first.

var txt = decodeURI(document.URL);
mu is too short
  • 426,620
  • 70
  • 833
  • 800
Ghostoy
  • 2,689
  • 19
  • 18
0
unescape('%7B & %7D');

this should help

Molecular Man
  • 22,277
  • 3
  • 72
  • 89