剑指Offer 第20题 判断字符串是否是数字の正则表达式
#include <regex>
regex pat1("[+-]?\\.\\d+([eE][+-]?\\d+)?");
regex pat2("([+-]?\\d+)(\\.(\\d+)?)?([eE][+-]?\\d+)?");
bool isNumericOfMine(const char *str)
{
if(str == NULL)
{
return false;
}
if(regex_match(str, pat2) || regex_match(str, pat1))
{
//cout << temp << "Regex Mathch!" << endl;
return true;
}
else
{
//cout << temp << "Regex Not Mathch!" << endl;
return false;
}
}
