FireFox无效正则表达式组 [英] FireFox invalid regex group

查看:90
本文介绍了FireFox无效正则表达式组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下正则表达式在

,到目前为止,并非在所有浏览器/JavaScript环境中都支持向后搜索.因此,如果要支持所有浏览器(包括旧版本),则实际上不能依赖该功能.

As you can see here, as of now, lookbehinds are not supported in every browser/JavaScript environment. Thus, you can't actually rely on that feature if you want to support all browsers including legacy versions.

由于您只想匹配除:和字符串中的第一个:之外的0+个字符,因此可以使用

Since you just want to match 0+ chars other than : and the first : in the string, you may use

s.match(/^[^:]*:/)

请参见 regex演示.

JS:

console.log(
 'Error 5: the lorem lipsum: in...'.match(/^[^:]*:/)[0]
);

这篇关于FireFox无效正则表达式组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆