Hello, I want to capture named substring with the pcre++ library.
I know the pcre library has the functionality for this, but pcre++ has not implemented this.
This is was I have now (just a simple example):
pcrepp::Pcre regex("test (?P<groupName>bla)");
if (regex.search("test bla"))
{
// Get matched group by name
int pos = pcre_get_stringnumber(
regex.get_pcre(),
"groupName"
);
if (pos == PCRE_ERROR_NOSUBSTRING) return;
// Get match
std::string temp = regex[pos - 1];
std::cout << "temp: " << temp << "\n";
}
If I debug, pos return 1, and that is right, (?Pbla) is the 1th submatch (0 is the whole match). It should be ok. But... regex.matches() return 0. Why is that :S ?
Btw. I do regex[pos - 1] because pcre++ reindexes the result with 0 pointing to the first submatch, so 1. So 1 becomes 0, 2 becomes 1, 3 becomes 2, etc.
Does anybody know how to fix this?