Hello folks! I'm trying to work with boost::regex but I'm stuck. I wrote the following code: //------------------------------------------------------------------- int main( int argc, CHAR* argv[] ) { boost::regex RegEx( "(eth\\d)" ); if ( boost::regex_match( "dsjkadhjksadjks eth1: ssgdsdhjasgdjg", RegEx ) ) { printf( "Found.\n" ); } return 0; } I tested the expression with Expresso and it's correct although it doesn't work in the code above. Is there something missing? My best regards Silvio
Silvio Reis Junior a écrit :
I tested the expression with Expresso and it's correct although it doesn't work in the code above. Is there something missing?
By default is matches the entire sentence. http://www.boost.org/doc/libs/1_36_0/libs/regex/doc/html/boost_regex/partial... http://www.boost.org/doc/libs/1_36_0/libs/regex/doc/html/boost_regex/introdu... « The algorithms regex_search and regex_match make use of match_results to report what matched; the difference between these algorithms is that regex_match will only find matches that consume all of the input text, where as regex_search will search for a match anywhere within the text being matched. » -- Mickaël Wolff aka Lupus Michaelis Racine http://lupusmic.org Blog http://blog.lupusmic.org
Thanks friend!
Now I understand it.
On Wed, Sep 3, 2008 at 10:50 AM, Mickael Wolff
Silvio Reis Junior a écrit :
I tested the expression with Expresso and it's correct although it doesn't work in the code above. Is there something missing?
By default is matches the entire sentence. < http://www.boost.org/doc/libs/1_36_0/libs/regex/doc/html/boost_regex/partial...
< http://www.boost.org/doc/libs/1_36_0/libs/regex/doc/html/boost_regex/introdu...
« The algorithms regex_search and regex_match make use of match_results to report what matched; the difference between these algorithms is that regex_match will only find matches that consume all of the input text, where as regex_search will search for a match anywhere within the text being matched. »
-- Mickaël Wolff aka Lupus Michaelis Racine http://lupusmic.org Blog http://blog.lupusmic.org
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Silvio Reis Junior wrote:
Hello folks! I'm trying to work with boost::regex but I'm stuck. I wrote the following code:
//------------------------------------------------------------------- int main( int argc, CHAR* argv[] ) { boost::regex RegEx( "(eth\\d)" ); if ( boost::regex_match( "dsjkadhjksadjks eth1: ssgdsdhjasgdjg", RegEx ) ) { printf( "Found.\n" ); } return 0; }
I tested the expression with Expresso and it's correct although it doesn't work in the code above. Is there something missing?
The docs for regex_match say: The algorithm regex_match determines whether a given regular expression matches all of a given character sequence denoted by a pair of bidirectional-iterators, the algorithm is defined as follows, the main use of this function is data input validation. The regexp in our example does not match all of the input, it seems to me. - Volodya
participants (3)
-
Mickael Wolff
-
Silvio Reis Junior
-
Vladimir Prus