//g++ --static regexbroke.cpp -I /boost_1_44_0/ -L /boost_1_44_0/stage/lib/ -lboost_regex -lpthread #include #include #include using namespace std; int main(int argc, char* argv[]) { bool broke =true; if(argc==2 && argv[1][0]=='1') broke=false; //string e="((?(?(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?(([0-5]\\d)|(\\b\\d)))([':])?\\s*(?(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([\":])?\\s*(?[NnSs])(([\\s,\"])|by|x|X)*(?((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?(([0-5]\\d)|(\\b\\d)))([':])?\\s*(?(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([\":])?\\s*(?[EeWw])))|((?(?[NnSs])\\s*(?(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?(([0-5]\\d)|(\\b\\d)))([':])?\\s*(?(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([\":])?(([\\s,\"])|by|x|X)*(?[EeWw])\\s*(?((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?(([0-5]\\d)|(\\b\\d)))([':])?\\s*(?(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([\":])?))|((?(?(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([':])?\\s*(?[NnSs])(([\\s,\"])|by|x|X)*(?((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([':])?\\s*(?[EeWw])))|((?(?[NnSs])\\s*(?(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([':])?(([\\s,\"])|by|x|X)*(?[EeWw])\\s*(?((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d)))((dg)|(deg)|(d))?\\s*(?(([0-5]\\d)|(\\b\\d))(\\.\\d+)?)([':])?))|((?(?(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d))(\\.\\d+))((dg)|(deg)|(d))?\\s*(?[NnSs])(([\\s,\"])|by|x|X)*(?((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d))(\\.\\d+))((dg)|(deg)|(d))?\\s*(?[EeWw])))|((?(?[NnSs])\\s*(?(([0-8]\\d)|(90)|(\\b\\d)|((?<=[NnSs])\\d?\\d))(\\.\\d+))((dg)|(deg)|(d))?(([\\s,\"])|by|x|X)*(?[EeWw])\\s*(?((0\\d\\d)|(1[0-7]\\d)|(180)|(\\b\\d\\d)|(\\b\\d)|((?<=[NnSsEeWw])\\d?\\d))(\\.\\d+))((dg)|(deg)|(d))?))"; string e1,e2,e3; if(broke){ e1="\\b(?(?\\d\\d)(?\\d\\d)(?\\d\\d(\\.\\d+)?)\\s+(?\\d{2,3})(?\\d\\d)(?\\d\\d(\\.\\d+)?))"; e2="\\b(?(?\\d\\d)(?\\d\\d(\\.\\d+)?)\\s+(?\\d{2,3})(?\\d\\d(\\.\\d+)?))"; e3="\\b(?
(?\\d\\d(\\.\\d+)?)\\s+(?\\d\\d\\d(\\.\\d+)?))"; } else{ e1="\\b(?(?\\d\\d)(?\\d\\d)(?\\d\\d(\\.\\d+)?)\\s+(?\\d{2,3})(?\\d\\d)(?\\d\\d(\\.\\d+)?))"; e2="\\b(?(?\\d\\d)(?\\d\\d(\\.\\d+)?)\\s+(?\\d{2,3})(?\\d\\d(\\.\\d+)?))"; e3="\\b(?
(?\\d\\d(\\.\\d+)?)\\s+(?\\d\\d\\d(\\.\\d+)?))"; } string reg="("+e1+")|("+e2+")|("+e3+")"; string::const_iterator start, end; string t = "[23:59] location 123456 123456"; start = t.begin(); end = t.end(); boost::regex r(reg, boost::regex::perl | boost::regex::icase); boost::smatch match; boost::match_flag_type flags = boost::match_default; while (boost::regex_search(start, end, match, r, flags)) { cerr << "DMdS:" << match["DMdS"].matched << endl; cerr << "DdM:" << match["DdM"].matched << endl; cerr << "dD:" << match["dD"].matched << endl; string key=""; if(broke==false){ if( match["DMdS"].matched) key="DMdS."; else if( match["DdM"].matched) key="DdM."; else if( match["dD"].matched) key="dD."; } cerr<< match.str()<