PCRE 不匹配

PCRE does not match

我想这是非常愚蠢的事情,但是这不匹配,我不知道为什么。 我成功编译了一切,但它不匹配。 我已经使用了 RE(".*"),但效果不佳。 系统是 OS X(使用 brew 安装的 pcre)。

std::string s;
if (pcrecpp::RE("h.*o").FullMatch("hello", &s))
{
    std::cout << "Successful match " << s << std::endl;
}

您正在尝试提取一个子模式(在 &s 中),但没有包含任何括号来捕获该子模式。试试这个(未经测试,注意括号)。

std::string s;
if (pcrecpp::RE("(h.*o)").FullMatch("hello", &s))
{
    std::cout << "Successful match " << s << std::endl;
}

http://www.pcre.org/original/doc/html/pcrecpp.html 的文档有一个类似的例子,说明:

Example: fails because there aren't enough sub-patterns:
!pcrecpp::RE("\w+:\d+").FullMatch("ruby:1234", &s);