int main() { std::string s = "Some people, when confronted with a problem, think " "\"I know, I'll use regular expressions.\" " "Now they have two problems."; std::regex self_regex("REGULAR EXPRESSIONS", std::regex_constants::ECMAScript | std::regex_constants::icase); if (std::regex_search(s, self_regex)) { std::cout << "Text contains the phrase 'regular expressions'\n"; } std::regex word_regex("(\\S+)"); auto words_begin = std::sregex_iterator(s.begin(), s.end(), word_regex); auto words_end = std::sregex_iterator(); std::cout << "Found " << std::distance(words_begin, words_end) << " words\n"; const int N = 6; std::cout << "Words longer than " << N << " characters:\n"; for (std::sregex_iterator i = words_begin; i != words_end; ++i) { std::smatch match = *i; std::string match_str = match.str(); if (match_str.size() > N) { std::cout << " " << match_str << '\n'; } } std::regex long_word_regex("(\\w{7,})"); std::string new_s = std::regex_replace(s, long_word_regex, "[$&]"); std::cout << new_s << '\n'; }
void SocketServer::run() { cout << "Server start at " << this->tcpServer.getPort() << endl; idCli = 0; string dataR; while (this->servRun) { this->tcpServer.waitConnectedClient(); for (int i = 0; i < this->tcpServer.getLastID(); i++) { if (this->tcpServer.isClientConnected(i)) { idCli = i; cout << "Client Add ID :" << this->tcpServer.getLastID() << endl; while (this->tcpServer.isClientConnected(idCli)) { dataR = this->tcpServer.receive(idCli); if (dataR != "") { //regex self_regex("SpeedLife ([0-9]+)",regex_constants::ECMAScript | regex_constants::icase); regex self_regex("PUSH But", regex_constants::ECMAScript | regex_constants::icase); smatch match; //cout << dataR << endl; if (regex_search(dataR, match, self_regex )) { this->dataLife->launchInvade = true; //std::cout << (unsigned int)stoul(match[1]) << " ok ok \n"; //this->dataLife->speedLifeGame = (unsigned int) stoul(match[1]); } //this->tcpServer.send(idCli, "You sent: " + dataR); } this->tcpServer.sleep(50); } cout << "Client Out" << endl; } } this->tcpServer.sleep(1000); } cout << "Server close" << endl; }