我正在查询SOLR服务器并需要处理前端的facet,我在更换sectionLabels的查询字符串时遇到问题。形成的查询如下:
var str = 'sectionlabel:%22Using%20Content%22+sectionlabel:%22Build%20Yours%22+sectionlabel:%22Skilled%20Level%3A%20Unleash%20your%20power%22';
问题:我需要从字符串中获取值,如下所示;
BuildYours 当前打印>>的%22Build%20Yours%22
所以,基本上,我需要使用正则表达式去除编码字符,我无法做到。任何帮助将不胜感激。
答案 0 :(得分:0)
这是你可以做到的一种方式 -
var arrWords = decodeURIComponent(str).split('+');
for (var i = 0; i < arrWords.length; i++) {
var label = arrWords[i].replace('sectionlabel:','');
$('#here').append(label + "<br />");
}
答案 1 :(得分:0)
这可能适合你
var str = 'sectionlabel:%22Using%20Content%22+sectionlabel:%22Build%20Yours%22+sectionlabel:%22Skilled%20Level%3A%20Unleash%20your%20power%22';
var str_decoded = decodeURIComponent(str);
var valNew =str_decoded.replace(/\"/g,'').replace(/sectionlabel:/g, '').split('+');
for (var i = 1; i < valNew.length; i++) {
$('#here').append(valNew[i] + "<br>");
}