簡體   English   中英

PCRE忽略C ++中的匹配項

[英]PCRE ignoring matches in c++

我正在嘗試在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(文本,&a,&b)

如果正則表達式中至少有兩個捕獲,每個返回參數一個,則只能返回true。 由於您的正則表達式(“林”)中沒有捕獲,因此無論模式是否與文本匹配,都保證re.PartialMatch返回false。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM