[英]FireFox invalid regex group
I have the following regex that works fine in chrome but it does not work in FireFox generating syntax error Invalid Regex Group
:我有以下正则表达式在chrome中工作正常,但在 FireFox 中不起作用,生成语法错误Invalid Regex Group
:
bld = txt.split(/(?<=:)/iu,1);
I have tried to escape :
using /(?<=\\:)/iu
but it gives the same error.我试图逃避:
使用/(?<=\\:)/iu
但它给出了同样的错误。 I could not able to figure out the cause of this problem.我无法弄清楚这个问题的原因。
As you can see here , as of now, lookbehinds are not supported in every browser/JavaScript environment.正如您在此处看到的,截至目前,并非每个浏览器/JavaScript 环境都支持后视。 Thus, you can't actually rely on that feature if you want to support all browsers including legacy versions.因此,如果您想支持包括旧版在内的所有浏览器,您实际上不能依赖该功能。
Since you just want to match 0+ chars other than :
and the first :
in the string, you may use由于您只想匹配字符串中除:
和第一个:
以外的 0+ 个字符,因此您可以使用
s.match(/^[^:]*:/)
See the regex demo .请参阅正则表达式演示。
JS: JS:
console.log( 'Error 5: the lorem lipsum: in...'.match(/^[^:]*:/)[0] );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.