Javascript 从POST响应中删除注释标记

Javascript 从POST响应中删除注释标记,javascript,jquery,regex,Javascript,Jquery,Regex,我正在使用JQuery并尝试发出post请求,而我得到的响应是 /*this is the string i need*/ 现在我正在尝试访问我需要的字符串,但是对于一些范围问题,我似乎没有得到正确的结果 我的代码是: $.get( "/geturl", function( data ) { console.log(hereStr(data)); ==> prints /*this is the string i need*/ }); function hereStr

我正在使用JQuery并尝试发出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只是打印带有注释标记的相同字符串,如上所示 我的正则表达式错了吗?或者这是一个范围问题

任何指点都将不胜感激
感谢您的
hereStr()
函数的更正版本:

function hereStr(f) {
  return f.replace(/\/\*(.+)\*\//, '$1');
}

这不是一个范围问题。你的
hereStr()
函数不正确。那么它应该是什么呢?
f.replace(/\/\*(.+)\*\/,“$1”)将提供注释开始和注释结束之间的所有内容。