I have the following code :
#include <iostream>
#include <regex>
using namespace std;
int main()
{
string s;
s = "server ('m1.labs.terad ata.com') username ('us er5') password('user)5') dbname ('def\\ault')";
regex re("(\'(.*?)\'\)");
sregex_token_iterator i(s.begin(), s.end(), re, 1);
sregex_token_iterator j;
unsigned count = 0;
while(i != j)
{
cout <<*i<< endl;
count++;
i++;
}
cout << "There were " << count << " tokens found." << endl;
return 0;
}
the regex above is meant to extract everything between the single quotes.
But how can I make the regex so that it is able to extract escaped single quotes (example username (user''5) should be extracted as 'user'5'.
Thanks in advance. I really need help with this . Had been trying for so many days.
Example
'm1.labs.terad ata.com'
'us er5'
'user)5'
'def\ault'
There were 4 tokens found. Please note that the single quote around the string should be there. Thanks in advance for help.
But now if my string is
s = "server ('m1.labs.terad ata.com') username ('us ''er5') password('user)5') dbname ('def\\ault')";
The output should be :
'm1.labs.terad ata.com'
'us 'er5' <<<<<<<<<<<<<<<<<<<
'user)5'
'def\ault'