说我在JavaScript中有以下字符串:
var text = "This is Table1, and the next table is Table2"
我需要通过添加Table1
来突出显示HTML中的Table2
和<b></b>
粗体,例如<b>Table1</b>
。使Table1 or 2
之前/之后的单词变得更加困难。
text.replace(/Table\d+/g, "<b>Table</b>"); // how to reserve the number for Table1 or Table2 here?
由于
答案 0 :(得分:0)
你可以做到
var text = "This is Table1, and the next table is Table2"
console.log(text.replace(/(Table\d+)/g, '<b>$1</b>'))
&#13;