I have this string to test:
"CPF char,
Nome char [80],
Idade int,
Salario double,
Sexo char,
Tem_Filhos bool,"
Or simply:
string testStatement("CPF char,\nNome char [80],\nIdade int,\nSalario double,\nSexo char,\nTem_Filhos bool,");
Here is my regEx:
regex createTableInside("(?:[ \\n\\t]*)(\\w*)(?:[ \\n\\t]+)(?:(?:(char)[ \\n\\t]*\\[[ \\n\\t]*(\\d*)[ \\t\\n]*\\])|(char)|(int)|(double)|(bool)|(bloob))(?:[ \\n\\t]*)(,)");
When i do a regex_search, it finds everything:
while(regex_search(testStatement, check, createTableInside))
{
for(index = 1; index < check.size(); index++)
{
if(check.str(index).compare("") == 0) continue;
cout << "\"" << check.str(index) << "\"" << endl;
}
aux = check.suffix();
}
Output:
"CPF"
"char"
","
"Nome"
"char"
"80"
","
"Idade"
"int"
","
"Salario"
"double"
","
"Sexo"
"char"
","
"Tem_Filhos"
"bool"
","
But when I do a regex_match, the check.size() always returns 0.
I've tested my regEx here: https://www.debuggex.com/, and it works.
I've also tried the match_any constant:
regex_match(testStatement, check, createTableInside, match_any);
Whats wrong?
Thanks.
#include <regex>and the default mac osx g++ compilerregex_search()will give you everything it possibly matches (groupwise), whileregex_match()might want to match the complete input. Are you sure that the complete input matches the expression?regex_matchdoesn't do sub-captures, so it just returns true or false, therefore no match info.