Each call to regex_search() generates one match. To get more than one, either call it in a loop, or use a regex iterator:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <regex>
#include <iostream>
#include <cstring>
int main()
{
std::regex rgx("Un");
constchar *target = "Unseen University - Ankh-Morpork";
for(auto it = std::cregex_iterator(target, target + std::strlen(target), rgx);
it != std::cregex_iterator();
++it)
{
std::cmatch match = *it;
std::cout << match.str() << '\n';
}
}
Un
Un
Works with clang++/libc++, but liveworkspace is down at the moment, so I can't demo. Note that this won't work with GCC, where regex is not implemented so you have to use boost.regex if that's your platform.