
Kay-Michael Wuerzner wrote:
Hello,
I have got a problem with the interpretation of the optionality operator '?' in boost::regex. Consider the following example (regex_test.cpp):
#include <iostream> #include
int main ( int argc, char** argv ) { boost::regex test ( "(Apple)? Iphone 3g" ); boost::match_resultsstd::string::const_iterator what;
std::string input ( argv[1] );
if ( 0 == boost::regex_match ( input, what, test, boost::match_default | boost::match_partial ) ) { std::cerr << "No Match\n"; } if ( what[0].matched ) { std::cerr << "Full Match\n"; } else { std::cerr << "Partial Match\n"; } return 0; }
Test runs are: ./regex_test "Apple Iphone" Output: Partial Match (as expected) ./regex_test "Apple Iphone 3g" Output: Full Match (as expected) ./regex_test "Iphone" Output: No Match and Partial Match (Why is that? "Apple" is optional should only be "Partial Match") ./regex_test "Iphone 3g" Output: No Match and Partial Match (Why is that? "Apple" is optional should be "Full Match")
The space is not optional in your expression. Regards, Roland