【问题标题】:JavaScript Unexpected Quantifier Error in Internet Explorer, but works in Google ChromeInternet Explorer 中的 JavaScript 意外量词错误,但在 Google Chrome 中有效
【发布时间】:2018-07-18 11:10:53
【问题描述】:

以下代码 sn-p 导致 Internet Explorer 引发 Unexpected Quantifier 错误,但 Google chrome 运行正常。

var regexWord = new RegExp("\\b(?<!-)"+lWord+"\\b(?!-)");

如何解决这个问题,使其跨浏览器工作?

更新

经过一些测试,错误似乎是正则表达式模式中(?<!-) 的结果。虽然,仍然不确定如何解决它。根据我阅读的正则表达式文档,这似乎是正确的。

【问题讨论】:

    标签: javascript regex google-chrome internet-explorer


    【解决方案1】:

    只有谷歌浏览器支持lookbehind ?<!

    所以用[^-] 替换(?<!-) 应该可以解决问题。

    【讨论】:

    • 它有效,但结果不同。您希望查看的部分包含在 [^-] 中,因此您需要在匹配后将其删除以获得相同的结果。
    猜你喜欢
    • 2019-11-22
    • 2018-06-25
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多