正则表达式匹配字符串中的最后一个浮点数 [英] Regex to match the last float in a string
本文介绍了正则表达式匹配字符串中的最后一个浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下字符串
translate3d(0px, -26px, 0px) scale(1);
我有以下正则表达式
(\d+)(?!.*\d)
问题是我的正则表达式只匹配最后一个整数而不是浮点数.如何修改它以识别字符串中的最后一个浮点数?
解决方案
要匹配浮点数,您可以使用以下正则表达式
\d+(?:\.\d+)?(?!.*\d)
I have the following string
translate3d(0px, -26px, 0px) scale(1);
And I have the following regex
(\d+)(?!.*\d)
The problem is that my regex just matches the last int number and not float. How to modify it in order to recognize also the last float number in a string?
解决方案
To match float number you can use following regex
\d+(?:\.\d+)?(?!.*\d)
If the ending is always );
then you can use following regex
\d+(?:\.\d+)?(?=\);$)
这篇关于正则表达式匹配字符串中的最后一个浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文