
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; } }

On 5/25/05, Wilkinson, John
const string float_regex = "([+-]?(([\\d]+\\.?)|(\\.[\\d]+)|([\\d]+\\.[\\d]+))){0,1}";
All of your groups are "capturing", which would explain all of the extra matches you get. You should make all but the outermost group in float_regex non-capturing using "(?:" instead of "(". -- Caleb Epstein caleb dot epstein at gmail dot com
participants (2)
-
Caleb Epstein
-
Wilkinson, John