Boost logo

Boost Users :

From: Marco Craveiro (marco_craveiro_at_[hidden])
Date: 2005-09-14 14:25:56


Hello boosters,

First, apologies if this has been discussed before - I did some googling
and could not find it. I've bumped into an interesting issue while using
Boost.Regex. The documentation states:

       http://www.boost.org/libs/regex/doc/basic_regex.html

       Effects: Constructs an object of class basic_regex. The
       postconditions of this function are indicated in the table:

       Element Value
       empty() true
       size() 0
       str() basic_string<charT>()

Using 1.33, I get empty() set to false with the default constructor. In
addition, if you attempt to search using an empty regex, the program
segfaults. The following example demonstrates the problem:

code:
------
#include <iostream>
#include <string>
#include <boost/regex.hpp>

int main() {
     std::string line("this is an example line");
     boost::smatch what;
     boost::regex re;

     std::cout << "re.empty(): " << re.empty() << std::endl;
     bool result = boost::regex_search(line, what, re);
}

output:
------
re.empty(): 0
Segmentation fault

This does not happen if I initialize the regex using an empty string (it
throws empty expression). Which leads to the main question (and the
reason why I discovered all of this): is it possible to make a regular
expression that matches anything? For instance, when using AWK, if you
define a rule without a pattern, i.e.:

{
        print $0;
}

I thought an empty regex would do the trick.

Regards,

Marco

-- 
in software development, the design document is a source code listing. -- jack reeves



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