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
(http://boost.org/libs/regex/doc/syntax_perl.html):

> 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
(http://open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1836.pdf) 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
alternates.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk