JavaScript 正则表达式错误
我有这个字符串:
£1,134.00 (£1,360.80 inc VAT)
我正在尝试提取数字以获得以下内容:
['1,134.00','1,360.80']
在 Javascript 中使用以下正则表达式模式:
/\d*,?\d+\.\d{2}/g
它在 Chrome 中工作正常,但我在 Opera 中收到此错误:
Uncaught exception: Syntax error, unrecognized expression: (£1,360.80 inc VAT)
Error thrown at line 75, column 784 in <anonymous function: k.error>(g) in http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js:
throw"Syntax error, unrecognized expression: "+g;
显然我希望它能在所有环境中工作现代浏览器,但我不知道是什么原因造成的。我还尝试了其他几种正则表达式模式,并研究了转义字符,因为我认为可能是这样。
有什么想法吗?
如果需要更多信息,请告诉我。谢谢
I have this string:
£1,134.00 (£1,360.80 inc VAT)
And I am trying to extract the numbers to get the following:
['1,134.00','1,360.80']
Using the following regex pattern in Javascript:
/\d*,?\d+\.\d{2}/g
It is working fine in Chrome, but I get this error in Opera:
Uncaught exception: Syntax error, unrecognized expression: (£1,360.80 inc VAT)
Error thrown at line 75, column 784 in <anonymous function: k.error>(g) in http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js:
throw"Syntax error, unrecognized expression: "+g;
Obviously I would like it to work in all modern browsers but I have no idea what is causing this. I have also tried several other regex patterns and have looked into escape characters as I thought it might be that.
Any ideas?!
Let me know if more info is needed. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法识别的表达式:(£1,360.80 inc VAT) <= 这不是您的正则表达式中的错误。你的绳子不是绳子。不知何故,它被混合并解释为 JavaScript 的一部分。
unrecognized expression: (£1,360.80 inc VAT) <= that's not an error in your regex. Your string is not being a string. Somehow it's getting mixed and interpreted as part of your javascript.