Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2005-02-18 12:08:27

> Why can I not construct a regex of the form: "|abc" (throws exception
> based on REG_EMPTY) for use with regex_match, if I want to match either
> "abc" or the empty string "". I understand thatn in a regex_search the
> empty string would always match (per Perl like semantics), and abc would
> never be considered. But, I want to use this with regex_match, where the
> empty string would have to match the entire string being searched. Work
> arounds such as "(?:)|abc" and "^$|abc" seem to get around this
> deficiency, but I am wondering why it is there in the first place.

It's deliberate, based on the assumption that empty alternatives are almost
always a mistake (as an aside, although these are allowed in Perl 5, Perl 6
will make them an error as well). POSIX regular expressions also requires
them to be diagnosed as errors. As you say the workaround is to use (?:) as
a placeholder for the empty string (I do need to update the docs to make
this clear though).


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