如何编写匹配浮点数的Python正则表达式?

如何编写匹配浮点数的Python正则表达式?

以下代码使用Python正则表达式匹配浮点数

更多Python相关文章,请阅读:Python 教程

示例

import re
s = '234.6789'
match = re.match(r'[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?',s)
print match.group()
s2 = '0.45'
match = re.match(r'[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?',s2)
print match.group()

输出

这将给出以下输出结果:

234.6789
0.45

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程