I am doing some work using regex in C++, tried both the std::regex and boost:regex (1.58.0).
And I am getting this weird matches. Here is the code:
#include <iostream>
#include <regex>
using namespace std;
int main(int argv, const char* argc[])
{
regex log_line_regex_(".+\\s(.+)$");
char* log_line = "06-29 18:20:08.938 1031 1099 D WifiStateMachine: processMsgConnect oo ModeState";
smatch matches;
if (regex_match(std::string(log_line), matches, log_line_regex_))
{
std::cout << "match: " << log_line << std::endl;
unsigned i;
for (i = 0; i < matches.size(); i++)
{
std::cout << "$" << i << ": " << std::string(matches[i].first, matches[i].second) << std::endl;
}
}
return 0;
}
The result is:
match: 06-29 18:20:08.938 1031 1099 D WifiStateMachine: processMsgConnect oo ModeState
$0: 06-29 18:20:08.938 1031 1099 D WifiStateMachine: processMsgConnect oo ModeSt`
$1: ModeSt`
See? The output is mangled :( As I said I tried with boost 1.58.0
and g++ (GCC) 4.9.2
both on Cygwin
I find it weird that boost::regex fails at this simple regex. So is my usage wrong?
Aucun commentaire:
Enregistrer un commentaire