2016-10-25 5 views
0

を高める「34.24は= nam12」に「= nam12 34.24」に、正規表現の作成を手伝ってください

boost::regex regex(); 
boost::cmatch result; 
std::string identifier; 
std::string value; 
if (boost::regex_match(assign.c_str(), result, regex)) 
{ 
    identifier = std::string(result[1].first, result[1].second); 
    value = std::string(result[2].first, result[2].second); 
} 
+0

にそれを参照してください - あなたはどのような正規表現を試してみましたか? – UKMonkey

+0

このコードの結果はどうしますか?表面的に見えるほどシンプルであれば、正規表現は過剰です。 –

+1

@PeteBecker私はstd :: istreamがこれには十分だと同意しますが、正規表現は実際には私にはあまりにも少なすぎます(抽出/検証なし)。 – sehe

答えて

2

を正規表現を作成私は彼がやり過ぎのことは知らないが、私はシンプルなためスピリットを使用したいですこのようなタスク:

#include <boost/spirit/include/qi.hpp> 

int main() { 
    std::string input; 
    while (std::getline(std::cin, input)) 
    { 
     std::string name; 
     double value; 

     using namespace boost::spirit::qi; 
     if (phrase_parse(input.begin(), input.end(), lexeme[+alnum] >> '=' >> double_, space, name, value)) 
      std::cout << "Parsed: name = '" << name << "' and value = " << value << "\n"; 
    } 
} 

Parsed: name = 'nam12' and value = 34.24 
Parsed: name = 'nam56' and value = 43.65 

のでLive On Wandbox

関連する問題