Boost logo

Boost Users :

From: Wilkinson, John (john.wilkinson_at_[hidden])
Date: 2005-05-25 09:34:35


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net