0
我有以下的javascript ...Regex.test是給我一個錯誤
$.post(url, data, function (json) {
var patt = new RegExp('/^\[{"dID":/');
if (patt.test(json)) {
//output json results formatted
} else {
//error so output json string
$('#diaryTable').replaceWith(json);
}
}, 'json');
基本上我的JSON要麼是一個有效的JSON與開始
[{ 「難道」:
或將是
[{的ex.Message從嘗試卡子E xception ...}]
Unfotunately我得到的錯誤JavaScript運行錯誤:預期 ']' 在正則表達式
我檢查我的正則表達式/^[{ 「爲什麼」:/時帶有一些測試數據的RegEx101.com和我的測試按預期工作。任何想法的人?
'VAR PATT =/^ \ [\ { 「爲什麼」:/;' –
你需要躲避'['支架,如否則它充當一個Regex操作符。如果你想測試正則表達式,我覺得'regexr'是最好的網站。 – somethinghere