0

I have the following string :

s = "server ('m1.labs.terada')ta.com') username ('user5') password('use r5') dbname ('default')";

I have defined a regex for extracting the values between the paranthesis,i.e m1.labs.terada')ta.com , user5.

regex re("\(\'[!-~]+\'\)");
sregex_token_iterator i(s.begin(), s.end(), re, 1);
sregex_token_iterator j;

However, I am not able to extract 'use r5'. Is there any way I can modify the regex to include white spaces as well?

hydra123
  • 337
  • 5
  • 14
  • Well, a space character is not between a `!` and a `~`. Your regular expression deliberately excludes it. Perhaps it shouldn't. – Igor Tandetnik Jul 19 '17 at 04:46
  • Okay. If i use the regex such as : regex re("(\'[!-~]+\x20*\')") . How can I match strings like ' user 5 user'?? – hydra123 Jul 19 '17 at 05:43
  • Your input string is not parseable using standard means. Are you sure the quote inside a string isn't supposed to be quoted? – rustyx Jul 19 '17 at 10:53
  • @RustyX Okay let the string be server ('m1.labs.teradata.com') username ('u5') password('uer 5') dbname ('default') How shall I parse this in cpp boost? – hydra123 Jul 19 '17 at 11:59
  • Your problem is this: if a token is allowed to contain spaces and parentheses and apostrophes, then why isn't `m1.labs.terada')ta.com') username ('user5') password('use r5') dbname ('default` one big token? In other words, your grammar is ambiguous. You first need to come up with a precise definition of "token" that excludes the above, but still includes `m1.labs.terada')ta.com` and `use r5`. Spell this out in plain English, and perhaps we'd be able to come up with a regex that formalizes this description. – Igor Tandetnik Jul 19 '17 at 12:17
  • @IgorTandetnik Yes, I am getting this token : m1.labs.terada')ta.com') username ('user5') password('use r5') dbname ('default as the output. However, I want the tokens as: token 1: 'm1.labs.terada')ta.com' token 2: 'user5' token 3 : 'use r5' – hydra123 Jul 19 '17 at 12:24
  • Again - explain to me, in plain English, why `m1.labs.terada')ta.com') username ('user5') password('use r5') dbname ('default` should **not** be considered a valid token. What rules on token syntax does it violate? Just saying "I want this" is not enough; [DWIM](http://www.catb.org/jargon/html/D/DWIM.html) system has yet to be perfected. – Igor Tandetnik Jul 19 '17 at 12:42
  • It does not violate any rule. I am confused as what to set the delimiter, so that token extracted is between " (' " " ') " – hydra123 Jul 19 '17 at 12:47
  • `m1.labs.terada')ta.com') username ('user5') password('use r5') dbname ('default` is in fact enclosed in `('` and `')`. If that's the rule, then it looks like you got the correct answer. If you don't consider this to be the correct answer, you need to figure out what's wrong with it, and formulate a different rule or set of rules. – Igor Tandetnik Jul 19 '17 at 12:50
  • I am not able to do that, I am only able to extract string between the quotes. but when there is space in the sting , it is causing a problm. – hydra123 Jul 19 '17 at 13:25

0 Answers0