我正在尝试用<span class="bold">my text between parenthases</span>
text.replace(/\[([^\][]+)]/g, "<span class='font-weight-bold underline'>$1</span>")
所以,如果我有this is my [name]
它将其替换为this is my <span class="bold">name</span>
我需要类似括号的内容。
如何在括号中全局替换文字?这并不像我想的那么简单。
答案 0 :(得分:2)
用text.replace(/\(([^\][]+)\) */g, "<span class='font-weight-bold underline'>$1</span>");
答案 1 :(得分:0)
试试这个......
text.replace(/ *\([^)]*\) */g, "<span class='font-weight-bold underline'>$1</span>");