入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

Python 正则表达式验证浮点数

创建时间:2014-09-10 投稿人: 浏览次数:3885
1. Mandatory sign, integer, fraction, and exponent
^[-+][0-9]+.[0-9]+[eE][-+]?[0-9]+$

2. Mandatory sing, integer, and fraction, but no exponent
^[-+][0-9]+.[0-9]+$

3. Optional sign, mandatory integer and fraction, and no exponent
^[-+]?[0-9]+.[0-9]+$

4. Optional sign and integer, mandatory fraction, and no exponent
^[-+]?[0-9]*.[0-9]+$

5. Optional sign, integer, and fraction. 
If the integer part is omitted, the fraction is mandatory.
If the fraction is omitted, the decimal dot must be omitted, too. No exponent
^[-+]?([0-9]+(.[0-9]+)?|.[0-9]+)$

6. Optional sign, integer, and fraction. 
If the integer part is omitted, the fraction is mandatory.
If the fraction is omitted, the decimal dot is optional. No exponent
^[-+]?([0-9]+(.[0-9]*)?|.[0-9]+)$

7. Optional sign, integer, and fraction. 
If the integer part is omitted, the fraction is mandatory.
If the fraction is omitted, the decimal dot must be omitted, too. Optional exponent
^[-+]?([0-9]+(.[0-9]+)?|.[0-9]+)([eE][-+]?[0-9]+)?$

8. Optional sign, integer, and fraction. 
If the integer part is omitted, the fraction is mandatory.
If the fraction is omitted, the decimal dot is optional. Optional exponent
^[-+]?([0-9]+(.[0-9]*)?|.[0-9]+)([eE][-+]?[0-9]+)?$

9. find float number in a larger body of text
[-+]?([0-9]+(.[0-9]+)?|.[0-9]+)([eE][-+]?[0-9]+)?

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。