如何编写匹配浮点数的 Python 正则表达式?
pythonserver side programmingprogramming更新于 2025/7/8 7:40:17
以下代码使用 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 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

