25 May
2005
25 May
'05
2:34 p.m.
I am trying to use regex to parse NMEA messages. I am new to regex and regular expressions in general, and am having problems getting regex_match to do what I want. The code below demonstrates the problem. I was hoping it would return: 1 1.2,3.4 2 1.2 3 3.4 instead it returns: 1 1.2,3.4 2 1.2 3 1.2 4 5 6 1.2 7 3.4 8 3.4 9 10 11 3.4 thanks John W. const string float_regex = "([+-]?(([\\d]+\\.?)|(\\.[\\d]+)|([\\d]+\\.[\\d]+))){0,1}"; const regex e( float_regex + "," + float_regex ); string str = "1.2,3.4"; smatch match; bool result = regex_match( str, match, e ); if ( result ) { for( int i = 0; i < match.size(); ++i ) { cout << i+1 << " " << match[i] << endl; } }