[Boost-users] boost matching \b and match_not_null flag

6 views
Skip to first unread message

Gavrilov, Roman

unread,
Jul 25, 2010, 7:55:36 AM7/25/10
to boost...@lists.boost.org

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

John Maddock

unread,
Jul 25, 2010, 12:47:54 PM7/25/10
to boost...@lists.boost.org
>I don't understand this behavior, am I missing something?

You have set a flag that says "never match a zero length string" and passed
a regular expression that can *only ever match a zero length string* ... as
a result no match can ever be found.

HTH, John.

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Gavrilov, Roman

unread,
Jul 26, 2010, 6:08:33 AM7/26/10
to boost...@lists.boost.org
Ohhhh, you're right.

Thanks.

Reply all
Reply to author
Forward
0 new messages