Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-05-31 00:45:24

impulse9 wrote:
> 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:
> boost::regex e("(\\d+)\\s*(kbit|)");

 From the Boost.Regex docs

> Empty alternatives are not allowed (these are almost always a mistake), but if you really want an empty alternative use (?:) as a placeholder, for example:
> "|abc" is not a valid expression, but
> "(?:)|abc" is and is equivalent, also the expression:
> "(?:abc)??" has exactly the same effect.

This would seem to be non-compliant behavior according to TR1, which
references ECMA-262, which describes the regex syntax in section 15.10.1 as:

> Pattern ::
> Disjunction
> Disjunction ::
> Alternative
> Alternative | Disjunction
> Alternative ::
> [empty]
> Alternative Term

The TR1 draft
( amends
ECMA-262 in a few ways, but says nothing that would indicate that empty
alternatives are not allowed.

FWIW, you could use Boost.Xpressive (new in 1.34), which allows empty

Eric Niebler
Boost Consulting

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