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}
v开发者_运维技巧ar 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("}",""));
}
Use decodeURI(document.URL)
first.
var txt = decodeURI(document.URL);
unescape('%7B & %7D');
this should help
精彩评论