Opened 14 years ago

Closed 14 years ago

#2188 closed Bugs (fixed)

Regex matches bad strings

Reported by: koen@… 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 John Maddock, 14 years ago

Milestone: Boost 1.36.0Boost 1.37.0
Status: newassigned

Confirmed as a bug, I'm looking for a fix now,

John Maddock.

comment:2 by John Maddock, 14 years ago

Resolution: fixed
Status: assignedclosed

Fixed in revision #48185.

Note: See TracTickets for help on using tickets.