0
我的應用程序具有用戶定義的正則表達式模式,最多可包含3個捕獲組。有沒有更好的方法來實現下面的代碼?PCRE PartialMatch組數
std::string glyph1, glyph2, glyph3;
switch (regex.NumberOfCapturingGroups())
{
case 0:
default:
found = regex.PartialMatch(word);
break;
case 1:
found = regex.PartialMatch(word, &glyph1);
break;
case 2:
found = regex.PartialMatch(word, &glyph1, &glyph2);
break;
case 3:
found = regex.PartialMatch(word, &glyph1, &glyph2, &glyph3);
break;
}
if (found) {
// ...
}
不幸的是,返回的值是假的,如果正則表達式會匹配,但有少捕獲組隨後要求。
雖然我喜歡這個想法,但我確定這不是pcrecpp的實現方式(pcre-8.36中沒有這個方法定義),我真的不想把自己的代碼添加到pcre中。 –