请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。
利用正则表达式






不加$的话

53表示数值的字符串

 




1 # -*- coding:utf-8 -*-
2 import re
3 class Solution:
4     # s字符串
5     def isNumeric(self, s):
6         # write code here
7         return re.match(r"[\+\-]?\d*(\.\d*)?([eE][\+\-]?\d+)?$",s)

 

相关文章:

猜你喜欢
  • 2022-01-01
  • 2021-10-03
  • 2022-12-23
  • 2021-10-13
  • 2021-07-14
  • 2022-12-23
  • 2022-02-02
相关资源
相似解决方案