表示数值的字符串(C++描述)

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

思路:用正则表达式

解题参考:https://blog.csdn.net/Jeff_Winger/article/details/82824144

正则文法知识点参考:https://www.cnblogs.com/wanghao-boke/p/12239945.html

https://www.cnblogs.com/cycxtz/p/4804115.html

https://www.cnblogs.com/coolcpp/p/cpp-regex.html

 1 #include<regex>
 2 
 3 class Solution {
 4 public:
 5     bool isNumeric(char* str)
 6     {
 7         string s = str;
 8         regex patten("[+-]?[0-9]*([.][0-9]+)?([eE][+-]?[0-9]+)?");
 9         
10         return regex_match(s, patten);
11     }
12 
13 };
原文地址:https://www.cnblogs.com/hemeiwolong/p/12502463.html