boost正则表达式匹配12345678910111213141516171819202122int TestRegexMatch(){ try { std::string a{ "http://192.1168.1.1:65535/123" }; boost::regex reg{ "^((http|https)://)?([\\w-]+\\.)+[\\w-]+(:([0-9]|[1-9]\\d|[1-9]\\d{2}|[1-9]\\d{3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]))?(/[\\w./?%&=-]*)?$" }; bool r = boost::regex_match(a.c_str(), reg); if (r) { printf("success"); } else { printf("failure"); } } catch (const std::exception& e) { printf("%s", e.what()); } return 0;} 查找1234567891011121314151617181920int TestRegexSearch(){ try { std::string a{ "http://192.1168.1.1:65535/123" }; boost::cmatch mat; boost::regex reg{ "^((http|https)://)?([\\w-]+\\.)+[\\w-]+(:([0-9]|[1-9]\\d|[1-9]\\d{2}|[1-9]\\d{3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]))?(/[\\w./?%&=-]*)?$" }; bool r = boost::regex_search(a.c_str(), mat, reg); if (r) { a = mat[0]; printf("find: %s\n", a.c_str()); } } catch (const std::exception& e) { printf("%s", e.what()); } return 0;}