You could build your solution on top of the example for regex_iterator
. If, for example, you know your delimiters are comma, period, semicolon, and hyphen, you could use a regex that captures either a delimiter or a series of non-delimiters:
([.,;-]|[^.,;-]+)
Drop that into the sample code and you end up with something like this:
#include <iostream>
#include <string>
#include <regex>
int main ()
{
// the following two lines are edited; the remainder are directly from the reference.
std::string s ("aaa,bbb.ccc,ddd-eee;");
std::regex e ("([.,;-]|[^.,;-]+)"); // matches delimiters or consecutive non-delimiters
std::regex_iterator<std::string::iterator> rit ( s.begin(), s.end(), e );
std::regex_iterator<std::string::iterator> rend;
while (rit!=rend) {
std::cout << rit->str() << std::endl;
++rit;
}
return 0;
}
Try substituting in any other regular expressions you like.