Boost logo

Boost Users :

From: Darin Adler (darin_at_[hidden])
Date: 2002-03-17 13:08:43


On 3/15/02 5:11 PM, "soleani" <anibal_at_[hidden]> wrote:

> So, it seems that the call to:
>
> static const boost::regex expression1( "\\" );
>
> makes it core dump.

Not sure why you got a core dump, but I do know what the problem is. The
regular expression code is throwing an exception because your expression is
bad. Try this program:

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

    int main()
    {
        try {
            boost::regex expression("\\");
        } catch (const boost::bad_pattern& p) {
            std::cout << "bad pattern: " << p.what() << '\n';
        }
    }

When you run it, you'll see that the expression causes a "bad_pattern"
exception because it has a backslash at the end. The problem is that you
have to escape the backslash once because of how C literals are interpreted
and again because of how characters in regular expressions are interpreted.

One fix is to use "\\\\" instead of "\\" so the backslash is escaped for the
regular expression:

    boost::regex expression("\\\\");

Another is to use the "literal" flag when creating the regular expression so
the backslash doesn't need to be escaped:

    boost::regex expression("\\", boost::regbase::literal);

Hope that helps.

    -- Darin


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