Hi i wish to get the values of the following expression : POLYGON(100 20, 30 40, 20 10, 21 21) Searching POLYGON(100 20, 30 40, 20 10, 21 21)
When i execute the following code i obtains this result :
POLYGON(100 20, 30 40, 20 10, 21 21)
result = 100 20
r2 = 100
r2 = 20
r2 = , 21 21
r2 = 21
size = 7
I don't know why i not obtains the middled values...
Thank for your help
#include <iostream> #include <boost/regex.hpp> using namespace std; void testMatch(const boost::regex &ex, const string st) { cout << "Matching " << st << endl; if (boost::regex_match(st, ex)) { cout << " matches" << endl; } else { cout << " doesn’t match" << endl; } } void testSearch(const boost::regex &ex, const string st) { cout << "Searching " << st << endl; string::const_iterator start, end; start = st.begin(); end = st.end(); boost::match_results<std::string::const_iterator> what; boost::match_flag_type flags = boost::match_default; while(boost::regex_search(start, end, what, ex, flags)) { cout << " " << what.str() << endl; cout << " result = " << what[1] << endl; cout << " r2 = " << what[2] << endl; cout << " r2 = " << what[3] << endl; cout << " r2 = " << what[4] << endl; cout << " r2 = " << what[5] << endl; cout << "size = " << what.size() << endl; start = what[0].second; } } int main(int argc, char *argv[]) { static const boost::regex ex("POLYGON\\(((\\-?\\d+) (\\-?\\d+))(\\, (\\-?\\d+) (\\-?\\d+))*\\)"); testSearch(ex, "POLYGON(1 2)"); testSearch(ex, "POLYGON(-1 2, 3 4)"); testSearch(ex, "POLYGON(100 20, 30 40, 20 10, 21 21)"); return 0; }