Hi I am implementing regex using C++ .
Background:
I have a std::string
and a std::regex
. I need to compare the string against this regex .
The regex used here is not about validation . My typical regex would be something
like
a[bc]{2}
and nothing beyond this scope
I have to pass this regex as a char pointer argument to a function .
Problem:
I am unable to assign char pointer to std::regex
. If I do so I am getting the following error.
terminate called after throwing an instance of std::regex_error what(): regex_error
My function body will be
std::string s((char*)a); // The main string
std::regex e((char*)b); // Regex comparing the main string. a and b are the parameters to the function
if (std::regex_match(s, e))
{
// returns the matched portion of the string
// for instance "abcdeef" , "e{2}" would return ee
}
else
{
// return "Mismatch"
}
Any suggestions..? Or is there a way to extract the string from regex like "a{2}b"
-> "aab"
Thanks in advance