Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2005-05-11 05:28:04


> I noticed some surprising behavior with match_partial and regex_search.
> Consider:
>
> regex e("abc|b");
> string str("ab");
> smatch what;
> if(regex_search(str, what, e, match_default | match_partial))
> {
> cout << (what[0].matched ? "full" : "partial") << '\n';
> }
>
> This code displays "partial". Clearly, regex_search is bombing out just as
> soon as it finds a match, partial or otherwise. But in this case, if it
> kept looking, it would find a full match. My understanding is that full
> matches are always preferred to partial matches. I couldn't find any
> discussion about this case in the regex docs or the std proposal. Did I
> miss it? What's the intention here? Is the std proposal underspecified?

It's so underspecified it's not there at all! (it got removed 'cos we
couldn't figure out the right wording, even though everyone agreed it was a
useful feature).

As far as current Boost.Regex is concerned: it prefers in order:

1) The leftmost match.
2) A full match.
3) The longest match (if it's a POSIX expression), otherwise a "depth first
search" match (Perl expressions).

It's the "leftmost" bit that's getting you here. To be honest I'm not sure
what the right thing to do is here, I can imagine situations when either a
full or a partial match would be the correct answer in this case.

At the very least, I'll have another look at the docs.

Thanks,

John.


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