Answer the question
In order to leave comments, you need to log in
How to write a regular expression for a string of numbers?
Below is a simple example of using a regular expression in C++. The user is expected to enter something like this: 23 123 123123 45 341 45. The length of the input can be any. But I need to not only validate whether there really is a string of numbers, but to catch each number in cmatch. No matter how much I try, it doesn't work, please help.
std::cmatch& result)
std::regex regular("(\\d\)\\s+");
if (std::regex_match(buff.c_str(), result, regular))
cout << "Size = " << result.size() << endl;
for (int i = 0; i < result.size(); ++i)
cout << result[i] << endl;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question