0

我正在使用 JQuery 并尝试发出发布请求,而我得到的响应是类型

/*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 只打印带有注释标签的相同字符串,如上所示我的正则表达式错了吗?或者这是一些范围问题?

任何指针将不胜感激谢谢

4

1 回答 1

2

hereStr()您的函数的更正版本:

function hereStr(f) {
  return f.replace(/\/\*(.+)\*\//, '$1');
}
于 2013-10-27T13:37:28.397 回答