简体   繁体   中英

PCRE ignoring matches in c++

I'm trying to work with C++ and PCRE regular expressions in Ubuntu. I installed almost every piece of software related (libpcrepp and similar), but I can't even match the simplest expression. My code, simplified:

#include <iostream>
#include <string>
#include <pcrecpp.h>

using namespace std;

int main() {

   std::string text, a, b;

   text = "Flowers in the forest are darker than in the prairie";

   pcrecpp::RE re("forest");

   if( re.PartialMatch(text, &a, &b) ) {
      std::cout << "match: " << a << b << "\n";
   }

}

No errors compiling:

g++ t2.cpp -lpcrecpp -o t2

And no results when executing. Any hint? Thanks in advance.

re.PartialMatch(text, &a, &b)

can only return true if there are at least two captures in the regular expression, one for each of the return arguments. Since there are no captures in your regular expression ("forest"), re.PartialMatch is guaranteed to return false, regardless of whether the pattern matches the text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM