Opened 14 years ago
Closed 14 years ago
#2188 closed Bugs (fixed)
Regex matches bad strings
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | Boost 1.37.0 | Component: | regex |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | regex false positive | Cc: |
Description
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 <iostream> #include <boost/regex.hpp>
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";
}
Change History (2)
comment:1 by , 14 years ago
Milestone: | Boost 1.36.0 → Boost 1.37.0 |
---|---|
Status: | new → assigned |
Confirmed as a bug, I'm looking for a fix now,
John Maddock.