1

私はpcrecpp c ++(PCRE lib)を使用
し、すべての一致をサイクルで取得する必要があります。どうすればできますか?

例:
「こんにちは」

件名:
「こんにちは、こんにちは」

サイクルは 3 回ループする必要があります (3 つの一致があるため)
1 ハロー
2 ハロー
3 ハロー

疑似コード

pcrecpp::RE pPattern ( "hello" );  
std::string strBase = "hello hello hello";  
// ...  
int iMatches = // Match count 
for ( int i = 1; i < iMatches; i++ )   
{  
    printf( "%d %s", i, pPattern[ i ].c_str () );  
}

pcrecpp.h でそれを行う方法のサンプル コードを教えてください。
私の悪い英語でごめんなさい。

4

1 に答える 1

4

この質問はすでに数か月前のものですが、ここで解決策を提供します。

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

int main(void)
{
  pcrecpp::RE regex("(hello)");  
  std::string strBase = "hello hello hello";  

  pcrecpp::StringPiece input(strBase);

  std::string match;

  int count = 0;
  while (regex.FindAndConsume(&input, &match)) {
    count++;
    std::cout << count << " " << match << std::endl;
  }
}

詳細については、このサイトが役立つ場合があります。

于 2013-06-28T12:32:50.503 に答える