hgiesel
hgiesel

Reputation: 5648

PCRE does not match

I suppose it's something very stupid, however this does not match, and I have no idea why. I compiles successfully and everything, but it just doesn't match. I've already used RE(".*") but it doesn't work as well. The system is OS X (installed pcre using brew).

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

Upvotes: 1

Views: 110

Answers (1)

Christopher Bruns
Christopher Bruns

Reputation: 9498

You are trying to extract one subpattern (in &s), but have not included any parentheses to capture that subpattern. Try this (untested, note parentheses).

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

The documentation at http://www.pcre.org/original/doc/html/pcrecpp.html has a similar example, stating:

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

Upvotes: 2

Related Questions