简体   繁体   中英

Regex to match the last float in a string

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)

Regex explanation

正则表达式可视化


If the ending is always ); then you can use following regex

\d+(?:\.\d+)?(?=\);$)

Regex explanation

正则表达式可视化

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM