|
Boost Users : |
From: John Maddock (john_at_[hidden])
Date: 2004-11-02 06:02:00
> I apologise in advance if this question is not direct to the right
> mailinglist, but this was the best I could find. The IRC channel also
> seems very quite... :)
Exactly the right list.
> I am currently experimenting with the boost::regex library, and so far it
> seems to do just the thing I need. However, when I have a regex
>
> "[0-9]+[a-zA-Z]+"
>
> And want to match this against the string
>
> "42foo 42bar"
>
> It returns false. This is (as far as I can see) due to the library not
> taking partial matches too, even when I set the boost::match_partial and
> boost::match_any flags (which, according to my interpretation, should be
> doing the trick).
>
> Here is my statement:
>
> bool success = boost::regex_match(subject->c_str(), returns, expression,
> boost::match_partial | boost::match_any);
You need to use regex_search, and *not* a partial match, these extracts from
the docs should make this clear:
regex_match: "Note that the result is true only if the expression matches
the whole of the input sequence. If you want to search for an expression
somewhere within the sequence then use regex_search. If you want to match a
prefix of the character string then use regex_search with the flag
match_continuous set.".
partial matches: "A partial match is one that matched one or more characters
at the end of the text input, but did not match all of the regular
expression (although it may have done so had more input been available)".
Hope this makes things clear.
John.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net