
Dick Bridges wrote:
I am trying to use Xpressive for parsing string-based message buffers.
<snip> You are confusing a backreference with a nested regex. A backreference (s1, s2, etc.) is accessed positionally from the match results struct like what[1], what[2], etc. In contrast, when you nest a regex in another regex, you ended up with nested match results. You can access them with what.nested_results(), which is a collection of nested results, each result corresponding to an invocation of a nested regex (and each of which may contain other nested results, ad infinitum). In your example ... sregex message_ = (*_s >> "FROGGIE" >> _ln >> +(+alnum >> *_s >> "=" >> *_s >> +_d >> *_s >> _ln) >> _ln); sregex re_ = +message_; smatch what; if( regex_search( buffer, what, re_ ) ) { cout << "Count: " << what.nested_results().size() << endl; BOOST_FOREACH(smatch const &msg, what.nested_results()) { cout << "Message:\n" << msg[0] << endl; } } This displays the three messages one at a time (as long as you add one extra newline at the end of the last messge, otherwise your regex only matches the first two messages). You'll notice that I eliminated your name_value_pair_ regex. That's because it exposed a bug in xpressive. :-P -- Eric Niebler Boost Consulting www.boost-consulting.com