I think what you're missing is that boost::regex
is the regular expression, but it doesn't do the parsing against a given input. You need to actually use it as a parameter to boost::regex_search
or boost::regex_match
, which evaluate a string (or iterator pairs) against the regular expression.
static const boost::regex e("<(From )?([A-Za-z0-9_]+)>(.*?)");
std::string chat_input("<Darker> Hello");
boost::match_results<std::string::const_iterator> results;
if (boost::regex_match(chat_input, results, e))
{
std::string playername = results[2]; //Get contents of the second (...)
}