【发布时间】:2015-07-02 16:41:24
【问题描述】:
如果我有这样的文字:
I need to bold *this* text and *that* text.
我需要将this文本和that文本加粗。
我需要同时转换为<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 场或更多场比赛。它正在这样做:
我需要加粗这个文本和那个文本和这个文本和那个文本。
【问题讨论】:
-
不好意思,看的问题太多了,虽然线路被拆分/爆炸了,为了不误导会删掉
-
"I need to bold *this* text and *that* text.".replace(/\*([^*]+)\*/g,"<b>$1</b>")
标签: javascript regex