Boost logo

Boost Users :

From: John Maddock (john_maddock_at_[hidden])
Date: 2002-11-20 06:38:55


> For example consider expression:
> (www\.)?(.+?)\.com
> When using match algorithm and try to match "www.somesite.com" $1 gets
"www.somesite" but I thought it should be "somesite". Why (www\.)? is
>ignored even when non greedy repeats are used?

Works just fine for me, using the test code below:

#include <iostream>
#include "boost/regex.hpp"

int main(int, char**) {
      boost::regex abc("(www\\.)?(.+?)\\.com");
      std::string s("www.somesite.com");
      boost::smatch what;
      boost::regex_match(s, what, abc);
      std::cout << (std::string)what[0] << std::endl
         << (std::string)what[1] << std::endl
         << (std::string)what[2] << std::endl;
      return 0;
}

John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/index.htm


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net