[Boost-bugs] [Boost C++ Libraries] #2188: Regex matches bad strings

Subject: [Boost-bugs] [Boost C++ Libraries] #2188: Regex matches bad strings
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-08-12 14:09:42


#2188: Regex matches bad strings
-------------------------------------+--------------------------------------
 Reporter: koen_at_[hidden] | Owner: johnmaddock
     Type: Bugs | Status: new
Milestone: Boost 1.36.0 | Component: regex
  Version: Boost Development Trunk | Severity: Problem
 Keywords: regex false positive |
-------------------------------------+--------------------------------------
 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";
 }

-- 
Ticket URL: <http://svn.boost.org/trac/boost/ticket/2188>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC