c++ - Boost Xpressive sregex assignment and capture group issue -


i notice strange behavior in boost xpressive sregex assignments. see code below. first code snippet not work has sregex has object preliminary assignments , being used in main expression later. second code snippet work has no prior sregex assignments (except final main one). please let me know if using boost xpressive api incorrectly.

code not work

  mark_tag value1(1), value2(2), value3(3), value4(4), value5(5), value6(6), value7(7);   boost::xpressive::sregex name,multicast,rtsp;    name = ( (value1 =  (+boost::xpressive::set[_w|_d|'-'|'_'|as_xpr(' ')]) )  >> ',' );    name1 =        ( (value2 = icase(as_xpr("mark1:") ) )     >> (value3 =  (+boost::xpressive::set[_d|'.']) )     >> ':'     >> (value4 =  (+boost::xpressive::set[_d]) ) >> optional(as_xpr(",")) );    name2 =        ( (value5 = icase(as_xpr("mark2:") ) )     >> (value6 =  (+boost::xpressive::set[_d|'.']) )     >> ':'     >> (value7 =  (+boost::xpressive::set[_d]) ) >> optional(as_xpr(",")) ) ;     boost::xpressive::sregex pt = bos     >> (     name     >> repeat<0,2>(     name1     |     name2)     )     >> eos;       boost::trim(string_to_parse);     smatch what;     if ( !regex_search(string_to_parse, what, pt)) {         std::stringstream ss;         ss << "unable parse: " << string_to_parse;         throw parse::myexception(ss.str());     }      std::string value1_str = what[value1]; // print them later     std::string value2_str = what[value2]; // print them later     std::string value3_str = what[value3]; // print them later     std::string value4_str = what[value4]; // print them later     std::string value5_str = what[value5]; // print them later     std::string value6_str = what[value6]; // print them later     std::string value7_str = what[value7]; // print them later 

string_to_parse = namex,mark1:192.168.1.100:5555,mark2:192.168.1.101:5556; (fails parsing) meaning what[<>] not contain value.

code works

   mark_tag value1(1), value2(2), value3(3), value4(4), value5(5), value6(6), value7(7);    sregex pt = bos     >> (     ( (value1 =  (+boost::xpressive::set[_w|_d|'-'|'_'|as_xpr(' ')]) ) >> ',' )     >> repeat<0,2>(     ( (value2 = icase(as_xpr("mark1:") ) ) >> (value3 =  (+boost::xpressive::set[_d|'.']) ) >> ':' >> (value4 =  (+boost::xpressive::set[_d]) ) >> optional(as_xpr(",")) )     |     ( (value5 = icase(as_xpr("mark2:") ) ) >> (value6 =  (+boost::xpressive::set[_d|'.']) ) >> ':' >> (value7 =  (+boost::xpressive::set[_d]) ) >> optional(as_xpr(",")) ) )     )     >> eos;      boost::trim(string_to_parse);     smatch what;     if ( !regex_search(string_to_parse, what, pt)) {         std::stringstream ss;         ss << "unable parse: " << string_to_parse;         throw parse::myexception(ss.str());     }      std::string value1_str = what[value1]; // print them later     std::string value2_str = what[value2]; // print them later     std::string value3_str = what[value3]; // print them later     std::string value4_str = what[value4]; // print them later     std::string value5_str = what[value5]; // print them later     std::string value6_str = what[value6]; // print them later     std::string value7_str = what[value7]; // print them later 

string_to_parse = namex,mark1:192.168.1.100:5555,mark2:192.168.1.101:5556; (passes parsing)

when match pattern nested regexes, nested match results. this explains all.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -