Perlでは、これを行うことができます:
$text = '1747239';
@matches = ($text =~ m/(\d)/g);
# @matches now contains ('1', '7', '4', '7', '2', '3', '9')
C ++正規表現マッチングを使用して、この動作を複製し、すべての一致を含む一致セットを取得するための最良の方法は何ですか?
私は今これを持っています:-
compiledRegex = std::regex(regex, std::tr1::regex_constants::extended);
regex_search(text, results, compiledRegex);
int count = results.size();
// Alloc pointer array based on count * sizeof(mystruct).
for ( std::cmatch::iterator match = results.begin();
match != results.end();
++match )
{
// Do something with match;
}
ただし、これは最初の一致のみを提供します。これは、/ gがないPerlと同じように問題ありませんが、/g効果が必要です。
それで、それを行うための良い方法はありますか、それとも正規表現を何度も実行し続ける必要がありますか?