I want to use boost::regex
to change the format of a bunch of dates on the format 19991231235959
to this format 1999-12-31_23:59:59
like this:
YYYYMMDDhhmmss --> YYYY-MM-DD_hh:mm:ss
19991231235959 --> 1999-12-31_23:59:59
I use this
std::string input = "19991231235959";
boost::regex regex("^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})");
std::string format = "\\1-\\2-\\3_\\4:\\5:\\6";
std::string output = boost::regex_replace(input, regex, format);
which works but is there a way to get rid of the repetitions ([0-9]{2})
in regex
construction and keep the match groups?