안녕하세요 저는 다음 식의 값을 얻고 싶습니다 : POLYGON (100 20, 30 40, 20 10, 21 21) POLYGON (100 20, 30 40, 20 10, 21 21)정규식 BoostRegex C++
다음 코드는 I이 결과 획득 실행할 때 :
POLYGON (100 20 30 40 20 10 21 21)
결과 = 100 20
R2 = 100
R2 = 20 개
R2를 =, 21 21
r2 = 21 당신의 도움을 위해사이즈 = 7
내가하지 middled 값을 얻는 이유를 몰라요 ...
감사
#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;
}