我正在尝试在C ++中执行模式匹配,格式为......
###.######## (example input would be 135.123551235)
我尝试了以下模式,但它与我输入的数据不匹配...
// get the points entered
getline(cin, x1ANDy1);
regex r("([0-9]+)\.([0-9]+)", regex_constants::basic);
if (regex_match(x1ANDy1, r))
{
cout << "Data has been entered properly.";
}
else
{
cout << "Data has been entered in the improper format, please re-enter your data.";
}
答案 0 :(得分:1)
这种模式将是&#34; \ d {3}。\ d {9}&#34;对于精确的3位数点(。)9位数或&#34; \ d {lowerbound,upperbound}。\ d {lowerbound,upperbound}&#34;如果你想允许某些数字量。或者如果您不想限制它,请将花括号替换为*。