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