id summary reporter owner description type status milestone component version severity resolution keywords cc 2188 Regex matches bad strings koen@… John Maddock "I wrote the following small program to test if a string is a valid ip. The regex gives a false positive for the case listed below. For comparison I've also added a perl program which does it correctly. #include #include bool regex_match(const std::string &text, const std::string &match) { try { const boost::regex regex(match); boost::smatch matches; return boost::regex_match(text, matches, regex); } catch(boost::regex_error &e) { return false; } } int main() { if(regex_match(""1.2.03"", ""^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])){3}$"")) { std::cout << ""GOOD :)\n""; } else { std::cout << ""BAD :(\n""; } } The corresponding perl program does it correctly: if('1.2.03' =~ m/^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])){3}$/) { print ""GOOD :)\n""; } " Bugs closed Boost 1.37.0 regex Boost Development Trunk Problem fixed regex false positive