I have the following string:
std::string s("server ('m1.labs.teradata.com') username ('use\\')r_*5') password('u\" er 5') dbname ('default')");
I have used the following code:
int main() {
std::regex re(R"('[^'\\]*(?:\\[\s\S][^'\\]*)*')");
std::string s("server ('m1.labs.teradata.com') username ('use\\')r_*5') password('u\" er 5') dbname ('default')");
unsigned count = 0;
for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), re);
i != std::sregex_iterator();
++i)
{
std::smatch m = *i;
cout << "the token is"<<" "<< m.str() << endl;
count++;
}
cout << "There were " << count << " tokens found." << endl;
return 0;
}
The output of the above string is :
the token is 'm1.labs.teradata.com'
the token is 'use\')r_*5'
the token is 'u" er 5'
the token is 'default'
There were 4 tokens found.
Now if the string s mentioned above in the code is
std::string s("server ('m1.labs.ter\'adata.com') username ('use\\')r_*5') password('u\" er 5') dbname ('default')");
The output becomes:
the token is 'm1.labs.ter'
the token is ') username ('
the token is ')r_*5'
the token is 'u" er 5'
the token is 'default'
There were 5 tokens found.
Now the output for both strings different: The expected output is "extract everything between the parenthesis and single quote i.e
the token is 'm1.labs.teradata.com'
the token is 'use\')r_*5'
the token is 'u" er 5'
the token is 'default'
There were 4 tokens found
The regex which I have mentioned in the code is able to extract properly BUT not able to escape "single quotes". It is able to escape ",) etc but not single quote. Can the regex be modified to produce the output I need. Thanks in advance.