C++ 正規表現文字列のキャプチャを機能させるように試みます。Windows と Linux、Boost とネイティブ C++ 0x11 の 4 つの組み合わせをすべて試しました。サンプルコードは次のとおりです。
#include <string>
#include <iostream>
#include <boost/regex.hpp>
//#include <regex>
using namespace std;
using namespace boost;
int main(int argc, char** argv)
{
smatch sm1;
regex_search(string("abhelloworld.jpg"), sm1, regex("(.*)jpg"));
cout << sm1[1] << endl;
smatch sm2;
regex_search(string("hell.g"), sm2, regex("(.*)g"));
cout << sm2[1] << endl;
}
動作する最も近いのは、Boost (1.51.0) を使用した g++ (4.7) です。そこでは、最初の cout が期待どおりに出力されますabhelloworld.
が、2 番目の cout からは何も出力されません。
-std=gnu++11 を指定した g++ 4.7<regex>
ではなく、<boost/regex.hpp>
出力を生成しません。
ネイティブを使用する Visual Studio 2012<regex>
は、互換性のない文字列反復子に関する例外を生成します。
Boost 1.51.0 を使用する Visual Studio 2008 では<boost/regex.hpp>
、「標準 C++ ライブラリの無効な引数」に関する例外が発生します。
これらのバグは C++ 正規表現にあるのでしょうか、それとも何か間違ったことをしているのですか?