Boost logo

Boost Users :

Subject: [Boost-users] [regex] using partial_match?
From: Armel Asselin (armelasselin_at_[hidden])
Date: 2013-03-19 09:02:15


[boost 1.53.0]

Hello,

I'd like to find in a stream of text either "abcd" or "ab". The text is not
bounded in size, so I think I should use partial_match.

However I present it the following text: "hello abc<cut_here>d, how are
you?"

it reports to find "ab" and does not wait for the second block to be
appended.

#include "boost/regex.hpp"

int main(int argc, char* argv[])
{
    boost::regex re ("abcd|ab");
    std::string str ("hello abc");

    boost::match_results<std::string::const_iterator> results;

    bool found = boost::regex_search (str.cbegin(), str.cend(), results, re,
boost::regex_constants::match_partial);

    if (!found || results[0].matched)
        printf("problem...\n");

    return 0;
}

Am I doing something wrong?
I see in the specification that "Specifies that if no match can be found,
then ....", isn't this specification flowed?
should not it be "if the regular expression engine needs to check past the
end of the block of text, and the start matches partially, ...." ?

I hope I am wrong and there are good flags to pass....

Regards
Armel


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