Not particularly well tested, but it matches your two cases:
^\s*#include\s+(<([^"'<>|\b]+)>|"([^"'<>|\b]+)")
The only problem is that due to the < and > thing, the result could be in capture group 2 or 3, so you should check if 2 is empty, then use 3... The advantage over some of the other answers is that it won't match sth like this: #include "bad.h> or this: #include <bad<<h>
And here's an example how to use (wrap) regcomp & friends:
static bool regexMatch(const std::string& sRegEx, const std::string& sSubject, std::vector<std::string> *vCaptureGroups)
{
regex_t re;
int flags = REG_EXTENDED | REG_ICASE;
int status;
if(!vCaptureGroups) flags |= REG_NOSUB;
if(regcomp(&re, sRegEx.c_str(), flags) != 0)
{
return false;
}
if(vCaptureGroups)
{
int mlen = re.re_nsub + 1;
regmatch_t *rawMatches = new regmatch_t[mlen];
status = regexec(&re, sSubject.c_str(), mlen, rawMatches, 0);
vCaptureGroups->clear();
vCaptureGroups->reserve(mlen);
if(status == 0)
{
for(size_t i = 0; i < mlen; i++)
{
vCaptureGroups->push_back(sSubject.substr(rawMatches[i].rm_so, rawMatches[i].rm_eo - rawMatches[i].rm_so - 1));
}
}
delete[] rawMatches;
}
else
{
status = regexec(&re, sSubject.c_str(), 0, NULL, 0);
}
regfree(&re);
return (status == 0);
}