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 above expression is intended to highlight everything between single quotes.
But how can I create a regular expression so that it can extract single quotes (for example, the username (user''5) should be extracted as "user'5".
Thanks in advance. I really need help with this. Spent so many days.
Example
'm1.labs.terad ata.com' 'us er5' 'user)5' 'def\ault'
4 tokens were found. Note that the single quotation mark around the string should be there. Thanks in advance for your help.
But now if my line
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'
source share