私はBoost.Regexを使用して、次のようなことを実現しています。「|」を検索する 次に、「|」の左側を取ります 右の部分と同じように、文字列を入れます。
string s1;
string s2;
who | sort
この後、s1は「who」になり、s2は「sort」になります。
よく覚えていれば、Pythonで可能でしたが、Boostで正規表現を使用してそれを行うにはどうすればよいですか?
ありがとうございました。
私はBoost.Regexを使用して、次のようなことを実現しています。「|」を検索する 次に、「|」の左側を取ります 右の部分と同じように、文字列を入れます。
string s1;
string s2;
who | sort
この後、s1は「who」になり、s2は「sort」になります。
よく覚えていれば、Pythonで可能でしたが、Boostで正規表現を使用してそれを行うにはどうすればよいですか?
ありがとうございました。
#include <boost/algorithm/string.hpp>
std::vector<std::string> strs;
boost::split(strs, "string to split", boost::is_any_of("|"));
ここに短いサンプルがあります:
#include <iostream>
#include <boost/regex.hpp>
int main()
{
// expression
boost::regex exrp( "(.*)\\|(.*)" );
boost::match_results<std::string::const_iterator> what;
// input
std::wstring input = "who | sort";
// search
if( regex_search( input, what, exrp ) ) {
// found
std::string s1( what[1].first, what[1].second );
std::string s2( what[2].first, what[2].second );
}
return 0;
}
さらに、 Boost.Tokenizerを調べたいと思うかもしれません。