Home Ask Login Register

Developers Planet

Your answer is one click away!

hgiesel February 2016

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;


Christopher Bruns February 2016

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);

Post Status

Asked in February 2016
Viewed 1,952 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life