Hi. I found some strange behaviors in Regex++. For details, please see the following source. These are bugs? or do I have mistaken? boost's version is 1.29.0. --- #include <iostream> #include <boost/regex.hpp> using namespace std; void p(const char *r, const char *s){ cout << endl << "*********" << endl; cout << "regex: " << r << endl; cout << "string: " << s << endl; cout << "result: " << (boost::RegEx(r).Search(s) ? "found" : "not found") << endl; } int main(){ // I think this must not match, but this do. p("a\\Z", "a\nb"); // These match. Correct behaviors. p("()", "abc"); p("^()", "abc"); p("^()+", "abc"); p("^(){1}", "abc"); // But these don't match. // Are these wrong? p("^(){2}", "abc"); p("^((){2})", "abc"); // I feel these somewhat strange. // But I have little confidence to say that this is a bug. p("()", ""); // found (OK) p("()\\1", ""); // not found (this must match?) p("()\\1", "a"); // found (OK) p("a()\\1b", "ab"); // found (OK) p("a()b\\1", "ab"); // not found (this must match?) return 0; } --- Kouhei Yanagita
Here is a test case.
int main(int argc, char* argv[]) { boost::regex expression; std::string asFind[5];
expression.assign("(?!foo)bar", boost::regbase::perl);
asFind[0] = "foobar"; asFind[1] = "??bar"; asFind[2] = "barfoo"; asFind[3] = "bar??"; asFind[4] = "bar";
for( int i = 0; i < 5; i++ ){ std::string s = asFind[i]; std::string::const_iterator start = s.begin(); std::string::const_iterator end = s.end(); boost::match_results<std::string::const_iterator> subexp; if (boost::regex_search( start, end, subexp, expression, boost::match_default)) { printf( "%s - Found.\n", s.c_str() ); } else { printf( "%s - Not Found.\n", s.c_str() ); } } return 0; }
The output is:
foobar - Not Found. ??bar - Not Found. barfoo - Found. bar?? - Found. bar - Found.
However, all the words should be "Found". Thank you for your time in advance.
Yes they should, it will be fixed in cvs shortly, thanks! John.
Hi. I found some strange behaviors in Regex++. For details, please see the following source. These are bugs? or do I have mistaken? boost's version is 1.29.0.
No you're quite right those are bugs - will be fixed in cvs shortly. thanks, John.
participants (2)
-
John Maddock
-
sugi@dream.big.or.jp