2017-09-18 8 views
0

yajraデータテーブルを再初期化すると、このエラーが発生します 未知のSyntaxError:無効な正規表現:/(^|.)dt(.|$)/:スタックオーバーフロー

考えられる原因は何か。

+0

これは何か関係があるかもしれませんが、いつ、どこで起こるのでしょうか? https://laravel.com/docs/5.5/validation#rule-regex – Loek

答えて

0

正規表現が実際に/(^|.)dt(.|$)/:の場合、末尾の:はjavascriptで正しくありません。正規表現は、/で開始し、終了する必要があります。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

ザ唯一のオプションはのG mは許容I U Y(後に最後/): https://regex101.com/r/l7mwwt/1

const regex = /(^|.)dt(.|$)\/:/gmiuy; 
 
const str = ``; 
 
let m; 
 

 
while ((m = regex.exec(str)) !== null) { 
 
    // This is necessary to avoid infinite loops with zero-width matches 
 
    if (m.index === regex.lastIndex) { 
 
     regex.lastIndex++; 
 
    } 
 
    
 
    // The result can be accessed through the `m`-variable. 
 
    m.forEach((match, groupIndex) => { 
 
     console.log(`Found match, group ${groupIndex}: ${match}`); 
 
    }); 
 
}

enter image description here

場合によっては/: litteralと一致させたい場合は、スラッシュをエスケープする必要があります。

関連する問題