如果我有類似的文字:粗體字*
I need to bold *this* text and *that* text.
我需要大膽這個文字和該文本。
我需要轉換爲<b>this</b>
和<b>that</b>
。
var str = $('textarea#commentfield').val();
var getBold = str.match(/\*.+\*/g);
if(getBold!=null){
getBold = getBold.toString().replace(/\*/g,"");
}
str = str.replace(/\*[^*]+?\*/g, "<b>"+getBold+"<\/b>");
這不是做什麼,我想爲2輪或更多的比賽。它不是做這個:
我需要大膽這個文本和文字和這個文本和文本。
對不起,看着太多的問題,雖然行被拆分/爆炸,將刪除,以免誤導 – atmd
'「我需要加粗*這個*文本和*那*文本。 [^ *] +)\ * /克, 「$ 1」)' – epascarello