
Hi there, I was under the expression that a regular expression which works with perl would also work with boost::regex. The following very simple test program doesn't work: if( boost::regex_match( "query", boost::regex( "q[u]" ))) { cout << "match" << endl; } else { cout << "no match" << endl; } whereas the perl equivalent works just fine: $text = "query"; if($text =~ m/q[u]/) { print "match!\n"; } else { print "no match\n"; } Meaning the perl code matches the regex inside $text and the boost::regex doesn't match. Can someone tell me what's wrong here with my thinking? And yes, I'm very new to regex overall. ;-) Thanks, Christian

On 10/30/2010 4:54 PM, Christian Henning wrote:
Hi there, I was under the expression that a regular expression which works with perl would also work with boost::regex. The following very simple test program doesn't work:
if( boost::regex_match( "query", boost::regex( "q[u]" ))) { cout << "match" << endl; } else { cout << "no match" << endl; }
You should read the docs. regex_match only returns true if the regex matches *all* of the input. Use regex_search. And read the docs. :-) -- Eric Niebler BoostPro Computing http://www.boostpro.com

Thanks Eric. I'm reading "Mastering Regular Expressions" by Jeffrey Friedl. ;-)
I'll make sure to read the boost::regex documentation, as well. I was
just carried away.
Thanks again.
Christian
On Sat, Oct 30, 2010 at 8:00 PM, Eric Niebler
On 10/30/2010 4:54 PM, Christian Henning wrote:
Hi there, I was under the expression that a regular expression which works with perl would also work with boost::regex. The following very simple test program doesn't work:
if( boost::regex_match( "query", boost::regex( "q[u]" ))) { cout << "match" << endl; } else { cout << "no match" << endl; }
You should read the docs. regex_match only returns true if the regex matches *all* of the input. Use regex_search.
And read the docs. :-)
-- Eric Niebler BoostPro Computing http://www.boostpro.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Christian Henning
-
Eric Niebler