首页 > 解决方案 > 正则表达式匹配带和不带逗号的数字和小数

问题描述

即使有逗号和小数,我也想匹配数字/小数。例如,我希望它能够匹配一个句子。数字可以在句子的中间、开头或结尾:

the number is 1000 today
the number is 1000.00 today
the number is 1000.142 today
the number is 1000.30 today
the number is 1000.200 today
the number is 1,000 today
the number is 1,000.00 today
the number is 1,000.142 today
the number is 1,000.30 today
the number is 1,000.200 today

我已经尝试过^\d*\.?\d+$,但似乎没有工作

标签: regex

解决方案


如果这确实是您的源数据,那么保持简单怎么样。

[0-9,.]+

https://regex101.com/r/QGtdsO/2/

在此处输入图像描述


推荐阅读