<p>“bla bla bla “Another THing”,more text to the sentence.”</p>
var str = '<p>“bla bla bla “Another THing”,more text to the sentence.”</p>'
str.replace(/“/,"<span class=quote>“</span>")
但由于句子中可能会有一些结束,我如何才能匹配最后一个?
解决方法:
您可以使用前瞻:
str = str.replace(/”(?=[^”]*$)/,"<span class=quote>”</span>")
这将替换“后面跟着一系列非”字符直到结尾.