Hello,

I’m trying to find word boundaries with regex_search and “\b” pattern.

I have the following code:

 

string buff = "aaaa*******\\b";

boost::match_flag_type flags = boost::match_default | boost::match_not_null;

boost::regex re("\\b");

boost::match_results<string::const_iterator> what;

 

string::const_iterator start = buff.begin();

string::const_iterator end = buff.end();

 

if ( regex_search(start, end, what, re, flags))

    {

        string out(start,what[0].second);

        cout << “match : " << out << endl;

    }

 

 

I would expect it to print “aaaa” in out string and to match the second boundary, but in fact it didn’t match anything.

If I remove the match_not_null flag then it will match the first boundary at the beginning of the string as expected.

 

I don’t understand this behavior, am I missing something?

Any help would be highly appreciated.

 

Thanks,

Roman