0
我使用jQuery和试图使一个post请求,并且我得到的回应是类型删除注释标记从POST响应
/*this is the string i need*/
现在,我试图访问我需要的字符串,但对于一些范围问题,我似乎没有把它做对。
我的代码是:
$.get("/geturl", function(data) {
console.log(hereStr(data)); ==> prints /*this is the string i need*/
});
function hereStr(f) {
return f.
replace(/^[^\/]+\/\*!?/, '').
replace(/\*\/[^\/]+$/, '');
}
但我的console.log只是打印如上图所示 是我正则表达式错误的注释标记相同的字符串?或者这是一些范围界定问题?
任何指针将不胜感激 感谢
这不是一个作用域的问题。你的'thisStr()'函数是不正确的。 – techfoobar
那该怎么办? – navinpai
'f.replace(/\/\*(.+)\*\//,'$ 1');''会在评论开始和评论结束之间给你一切。 – techfoobar