PCRE忽略了C 中的匹配

PCRE ignoring matches in c++

本文关键字:PCRE      更新时间:2023-10-16

我正在尝试与ubuntu中的C 和PCRE正则表达式合作。我几乎安装了与软件相关的所有软件(libpcrepp和类似),但我什至无法匹配最简单的表达式。我的代码,简化:

#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";
   }
}

没有错误编译:

g++ t2.cpp -lpcrecpp -o t2

执行时没有结果。有暗示吗?预先感谢。

re.partialMatch(text,&amp; a,b)

只有在正则表达式中至少有两个捕获时,才能返回true,一个用于每个返回参数。由于您的正则表达式中没有捕获("森林"),因此保证partialMatch返回false,无论该模式是否与文本相匹配。