regexes matching empty strings

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. Thanks, Michael Goldshteyn

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). John.

Interesting, I guess I hadn't thought of writing something like "abc|" simple as (?:abc)? Thanks Mike "John Maddock" <john@johnmaddock.co.uk> wrote in message news:05c001c515dd$8b7232c0$3ef20352@fuji...
"(?:)|abc" and "^$|abc" seem to get around this deficiency, but I am wondering why it is there in the first place.
Remember also that:
|x is the same as x??
x| is the same as x?
John. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
John Maddock
-
Michael Goldshteyn