请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。
1 # -*- coding:utf-8 -*- 2 import re 3 class Solution: 4 # s字符串 5 def isNumeric(self, s): 6 if len(s) == 0: 7 return False 8 pattern = '[+-]?\d*(\.\d+)?([eE][+-]?\d+)?' 9 result = re.search(pattern,s) 10 if result != None and result.span() == (0,len(s)): 11 return True 12 else: 13 return False 14 # write code here