javascript – 匹配最后一次出现的“

我有一个字符串可能如下所示:

<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>")

这将替换“后面跟着一系列非”字符直到结尾.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...