【发布时间】:2021-03-20 00:32:36
【问题描述】:
我试图抓取两组双下划线之间的内容,并在两个下划线html标签之间替换它,但我的正则表达式不太正确。
const str = "__test__"
str.replace(/__(\wd+)__/g, "<u>$1<\/u>")
console.log(str)
预期输出:<u>test</u>
【问题讨论】:
-
我想你的意思是
__(\w+)__和<u>$1</u> -
或
/__([^\W_]+(?:_[^\W_]+)*)__/g -
@Thefourthbird 哎呀,我忘记了示例中的结束标签,这是为了转义(我认为)。
标签: javascript html regex markdown