|
Boost : |
From: John Maddock (boost.regex_at_[hidden])
Date: 2003-10-10 06:23:05
> Incidentally, do you have any idea about what I'm doing wrong with
> match_partial
> http://article.gmane.org/gmane.comp.lib.boost.user/4569
>
> (Ok, I know that was sly ;-)
No problem, for some reason that one hasn't shown up in my inbox, anyway:
>I'm afraid I haven't got the hang of match_partial.
>
>Below is a little code with two functions that I think should produce
>identical results, but don't.
>
>In strip_commas_try1 I use:
> boost::regex const front("^( *[[],*)(.*)$");
> regex_match(it, end, what, front);
>In strip_commas_try2 I use:
> boost::regex const front("^( *[[],*)");
> regex_match(it, end, what, front, boost::match_partial);
>
>Why does this second case not result in
> what[0].matched
There are two errors in your code:
1) you should check the return value of regex_match to see if there is some
kind of match before checking what[0].matched to see if it was partial or
not.
2) The second match fails because you called regex_match and the expression
cannot match *all* of the text. If you want to match *some* of the text
then use regex_search. The match_partial flag will only come into play if
all of the text is matched, but not all of the expression.
John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk