Since you don't know how many ranges there are, you have to populate a data structure that can grow as needed, not an array. I'll use a vector of strings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <string>
#include <iostream>
#include <vector>
#include <regex>
int main()
{
std::string in = "1-2,3,4-5,6-7,8-11,12,100-123";
std::regex re("(\\d+(-\\d+)?),?");
std::vector<std::string> out( std::sregex_token_iterator(in.begin(), in.end(), re, 1),
std::sregex_token_iterator() );
for(auto& s: out)
std::cout << "\"" << s << "\"\n";
}
Tested with Visual Studio 2012 and Clang++ 3.1/libc++-svn.
If you #include <boost/regex.hpp> and use boost::regex/boost::sregex_token_iterator, this will work with GCC as well.