What is the right regular expression to identify a floating point number such that only the decimal point and one number is required.
re = QRegExp("[-+]?[0-9]*\\.[0-9]+");
if (re.exactMatch(s))
std::cout<< "Double"<<std::endl;
This code identifies 3.1
and .1
as double but not 3.
. The trouble is, that if I make the second number block optional (replacing +
with a *
) then .
would also be a double. How can I fix that?
I use Qts regular expression library, but I guess std::regex
would work the same.