F
F
Fortunato282018-09-15 07:27:07
C++ / C#
Fortunato28, 2018-09-15 07:27:07

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

1 answer(s)
V
Vladimir S, 2018-09-15
@Fortunato28

check regex (\d+)\s*
in coderegular("(\\d+)\\s*");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question