1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>
#include <string>
#include <map>
#include <regex>
int main()
{
std::map<std::string, std::string> vers
{
{"a", "someProgram-Ver-11_11"},
{"b", "someOtherProgram-Ver-2_13"},
{"c", "anotherProgram-Ver-5.11"},
{"d", "anotherProgram-Ver-55_110"},
{"e", "anotherProgram-Ver-5555_11"},
{"f", "anotherProgram-Ver-205_11"}
};
std::smatch m;
std::regex reg_1{"[0-9]{1,20}_[0-9]{1,10}"};
std::regex reg_2{"_"};
std::string output;
std::vector<std::string> vals;
for (auto& [k, v] : vers)
{
if(regex_search(v, m, reg_1) )
{
regex_replace
(std::back_inserter(output), v.begin(), v.end(), reg_2, ".");
vals.push_back(output);
output.clear();
}
}
for(auto i:vals)
{
std::cout << i << '\n';
}
return 0;
}
|