将REGEXP构造函数转换为与Safari兼容的
我有这个正则构造的模式,我将字符串变量传递到。这在Chrome中非常有效,但在Safari中不起作用。
有没有办法将此代码转换为在浏览器中兼容?谢谢你!
(e = e
.split(new RegExp("(?<!\\w)" + t[l] + "(?!\\w)(?![^\\[\\]]*\\])", "gm"))
.join(n)),
1 == caseinsensitive &&
(e = e.replace(
new RegExp("(?<!\\w)" + t[l] + "(?!\\w)(?![^\\[\\]]*\\])", "gmi"),
"[$&](" + n + ")"
));
I have this regexp constructed pattern I'm passing a string variable to. This works perfectly in Chrome, but won't work in Safari.
Is there a way I might be able to convert this code to be compatible across browsers? Thank you!
(e = e
.split(new RegExp("(?<!\\w)" + t[l] + "(?!\\w)(?![^\\[\\]]*\\])", "gm"))
.join(n)),
1 == caseinsensitive &&
(e = e.replace(
new RegExp("(?<!\\w)" + t[l] + "(?!\\w)(?![^\\[\\]]*\\])", "gmi"),
"[amp;](" + n + ")"
));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
(?!\ b \ w)
负面lookahead如果下一个char是一个字char,则需要一个单词边界位置。否则,如果下一个char不是字char,则无需单词边界。You can use
The
(?!\B\w)
negative lookahead requires a word boundary position if the next char is a word char. Else, if the next char is not a word char, no word boundary is required.