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("('[^']*(?:''[^']*)*')");
// I have used -1 to extract everything apart from the content there in brackets.
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 the argument name such as server, username, password etc.
But this is the output I am getting:
server (
) username (
) password(
) dbname (
)
There were 5 tokens found.
But the output I was expecting is :
server
username
password
dbname
There were 4 tokens found.
Please help me where I am missing out. Thanks in advance