Edit8:同じ問題で私の後に来るかもしれない人のために最初に解決策を投稿しました。
解決策:
()演算子を呼び出す代わりに、=で正規表現を割り当てました。うまくいきました。それは愚かでした。
#include <iostream>
#include <string>
#include <boost/xpressive/xpressive_dynamic.hpp>
int main()
{
std::string str = "foobarfoo";
boost::xpressive::sregex rex;
std::string rstr = "foo";
rex = boost::xpressive::sregex::compile(rstr, boost::xpressive::regex_constants::ECMAScript);
if (boost::xpressive::regex_search(str, rex, boost::xpressive::regex_constants::match_continuous))
std::cout << "Match found.";
else
std::cout << "No match found.";
return 0;
}
元の問題:
私はしばらくの間xpressiveと戦ってきましたが、まだ何も機能していません。次のコードで:
#include <iostream>
#include <string>
#include <boost/xpressive/xpressive_dynamic.hpp>
int main()
{
std::string str = "foobar";
boost::xpressive::sregex rex;
std::string rstr = "foo";
rex(boost::xpressive::sregex::compile(rstr));
if (boost::xpressive::regex_match(str, rex))
std::cout << "Match found.";
else
std::cout << "No match found.";
return 0;
}
期待する一致が見つかりません。助けていただければ幸いです。
編集:正規表現のコンパイル行を次のように変更してみました
rex(boost::xpressive::sregex::compile(rstr, boost::xpressive::regex_constants::ECMAScript));
まだ何もありません。
Edit2:MinGWGCC4.7でコンパイル
Edit3:正規表現文字列が宣言されている行を両方に変更してみました
std::string rstr = ".*";
と
std::string rstr = "(.*)";
まだ何もありません。
Edit4:次の情報はありませんが、結果はありません。
#include <iostream>
#include <string>
#include <boost/xpressive/xpressive_dynamic.hpp>
int main()
{
std::string str = "foobarfoo";
boost::xpressive::sregex rex;
std::string rstr = "(foo)";
rex(boost::xpressive::sregex::compile(rstr));//;, boost::xpressive::regex_constants::ECMAScript));
if (boost::xpressive::regex_search(str, rex, boost::xpressive::regex_constants::match_default))
std::cout << "Match found.";
else
std::cout << "No match found.";
return 0;
}
Edit5:この時点で、strの最初と最後の両方に「foo」が2つ一致することを期待しています。
Edit6:少なくともプレフィックスを取得できることを期待して、match_continuousフラグを設定してregex_searchを実行しようとしました。サイコロはありません。また、ECMAScriptフラグを使用してコンパイルし、match_defaultフラグとmatch_continuousフラグの両方を使用してregex_searchを実行してみました。
Edit7:strstr()がここで機能することはわかっています。これは単純なサンプルケースだからです。実際のアプリケーションでは、ブーストが不可欠です。