我有代碼:
var word = 'thisistheword';
var string = 'istheword';
console.log(word.replace(new RegExp(string, "gi"), "<b>" string "</b>"));
現在我得到了this<b>istheword</b>,但我想收到反轉的結果,所以:<b>this</b>istheword。
uj5u.com熱心網友回復:
var word = 'thisistheword';
var string = 'istheword';
console.log(word.replace(new RegExp("(.*)" string , "gi"), "<b>$1</b>" string));
給出:<b>this</b>istheword
"(.*)" string表示匹配前面的所有內容string。包裹起來,()以便您以后可以使用$1
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/527113.html
