I'm doing my miniSQL and trying to use regex to parse query statements.
Though succeeded in handling the case "create table a(a int, b int)", I failed to handle to case when nested brackets existing.
I'm just wondering what's wrong with my code : P
int main()
{
// std::string first = "create table a(a int, b1 int)"; it prints (a int, b1 int), works!
std::string cmd = "create table a(a int, b1 int, c char(20))"; // failed to prints (20) only
const regex pattern("[\\(]((\\w+)|(,)|(\\s+))*[\\)]");
const sregex_token_iterator end;
for (sregex_token_iterator it(cmd.begin(), cmd.end(), pattern); it != end; it ++ )
{
cout << *it << endl;
}
return 0;
}