extern"C" {
__declspec(dllexport) int __cdecl regex(std::string target,std::string rgx, std::vector<std::cmatch*>* matches, std::vector<int*> *ints)
{
// this can be done using raw string literals:
// const char *reg_esp = R"([ ,.\t\n;:])";
std::regex rgxa = std::regex(rgx);
constchar *targetA = target.c_str();
std::regex_iterator<constchar*> it;
std::cmatch *match = NULL;
for(it = std::cregex_iterator(targetA, targetA + std::strlen(targetA), rgxa);
it != std::cregex_iterator();
++it)
{
match = new std::cmatch(*it);
matches->push_back(match); //it //data inserted via push_back(*match)
std::cout << match->str() << '\n'; //this call works, displays useful information (e.g. "Un" for ("Unseen University", "Un) example, as below)
}
return EXIT_SUCCESS;
}
}
Output:
1 2 3 4 5
Un
Un
However, using a call to regex function, and THEN (from OUTSIDE the regex func) trying to display the data in the std::vector<std::cmatch*> produces output:
1 2 3 4 5 6
▌▌
▌▌
▌▌
▌▌
The call to regex is as:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
intMyReturnVal = regex("Unseen University", "Un", matches, ints);
for(int i = 0; i < matches->size(); i++)
{
std::cmatch match = matches->at(i);
std::cout << match->str() << endl; //doesn't work
std::cout << matches->at(i)->str() << std::endl; //doesn't work
}
yep, match_results is a (typically), vector of sub_matches, and a sub_match is a pair of iterators into the original string (and in case of a character array, as here, they are pointers).