I am trying to parse HTTP headers with POSIX ERE regex library (C GNU Regex library in regex.h, and yes, I know about boost). I am using pattern:
([0-9a-zA-Z-]*):[[:space:]]*(.*)[[:space:]]*\r\n(.*)
(last group for recursive parse), my headers:
HTTP/1.1 200 OK\r\nServer: nginx/0.9.2\r\nDate: Tue, 15 Jul 2014 15:08:12 GMT\r\nContent-Type: text/plain;charset=UTF-8\r\nConnection: keep-alive\r\n
I have checked this pattern in Regex Buddy 3.1.1 and it matches, but my code somehow returns no matches, although it works normal in other situations. Can anyone help me with this?
regcomp(&compiledRegEx,pattern.c_str(), compileFlags);
size_t numberOfSubExpressions = compiledRegEx.re_nsub + 1;
matches = new regmatch_t[numberOfSubExpressions];
auto errorCode = regexec(&compiledRegEx,expression.c_str(),numberOfSubExpressions,matches,REG_EXEC_FLAGS);
if (errorCode == REG_EXEC_SUCCESS)
{
for (size_t i = 0; i < numberOfSubExpressions; ++i)
{
// If no matches left - break out
if (matches[i].rm_so == -1 || matches[i].rm_eo == -1) break;
// Extracting substring and adding to results // eo points to the character after the last one
std::string subString = expression.substr(matches[i].rm_so, matches[i].rm_eo - matches[i].rm_so);
results.push_back(subString);
}
...