Boost logo

Boost :

From: impulse9 (impulse9_at_[hidden])
Date: 2007-05-30 17:03:34

Hi All,

I've just started to use boost::regex I met with the following
incompatibility with Perl regular expressions:

It is impossible to use empty expressions,
neither alone nor inside of another regex statement.

Sample code:

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

void check_regexp(const char * text)
        boost::regex e("(\\d+)\\s*(kbit|)");
        boost::cmatch what;
        if (boost::regex_match(text, what, e))
            std::string item1(what[1].first, what[1].second);
            std::string item2(what[2].first, what[2].second);
                << "matched. " << std::endl
                << "Value : " << item1 << std::endl
                << "Units : " << item2 << std::endl
                << std::endl;
    catch (boost::regex_error & e)
        std::cout << "ERROR: " << e.what() << std::endl;

int main(int argc, char** argv)
    check_regexp("96 kbit");

Program output:

ERROR: Empty expression

Such regular expressions are quite legal in Perl (e.g. /(Ann|Bob|)/)

One possible (quick-n-dirty) workaround for this is to replace
  boost::regex e("(\\d+)\\s*(kbit|)");
  boost::regex e("(\\d+)\\s*(kbit|.{0})");

Program output would be:
Value : 96
Units : kbit
Would it be considered as an issue for further improvement?

Thank you.


Boost list run by bdawes at, gregod at, cpdaniel at, john at