I have an ugly mess of a string, that is composed of several URIs.
:/SymbolStandards/JMSymbology/MIL_STD_2525D_Symbols/0_301_0.svg,:/SymbolStandards/JMSymbology/MIL_STD_2525D_Symbols/02011.svg,:/SymbolStandards/JMSymbology/MIL_STD_2525D_Symbols/02012.svg,:/SymbolStandards/JMSymbology/MIL_STD_2525D_Symbols/02110000.svg
What I would like to do is strip out every occurrence of the characters :/.,, so I can have a single string that would be a valid filename.
I've written this simple regex expression in order to do jus that: [^(:/,.)]
It seems to be the correct regex expression, according to http://www.regexpal.com/.
However, when I run the following C++ code, I do not get back what I was expecting(just alphanumeric characters and underscores), I just get back the first alphanumeric character in the sequence: S.
What am I doing incorrectly with std::regex, or is my regex expression off?
#include <iostream>
#include <regex>
#include <string>
static const std::string filenames {R"(:/SymbolStandards/JMSymbology/MIL_STD_2525D_Symbols/0_301_0.svg,:/SymbolStandards/JMSymbology/MIL_STD_2525D_Symbols/02011.svg,:/SymbolStandards/JMSymbology/MIL_STD_2525D_Symbols/02012.svg,:/SymbolStandards/JMSymbology/MIL_STD_2525D_Symbols/02110000.svg)"};
static const std::regex filename_extractor("[^(:/,.)]");
int main() {
std::smatch filename_match;
if(std::regex_search(filenames, filename_match, filename_extractor))
{
std::cout << "Number of filenames: " << filename_match.size() << std::endl;
for(std::size_t i = 0; i < filename_match.size(); ++i)
{
std::cout << i << ": " << filename_match[i] << std::endl;
}
}
return 0;
}
std::regex_replacebut this is probably better not using regex at all. Maybe look at std::remove_if. - Galik,:/, not:/,? Can't you split on that instead? - rustyx