i using boost regex, confused syntax used boost regex. if want use pattern "bb" match string "aabbcc", have make pattern "bb" ".*bb.*" string matched. wired because in perl don't need add ".*" @ front , end of "bb". did miss boost regex or flavor of boost regex? below simple source code question:
#include <boost/regex.hpp> #include <iostream> #include <string> int main() { boost::regex regex_bb01("bb"); boost::regex regex_bb02(".*bb"); boost::regex regex_bb03("bb.*"); boost::regex regex_bb04(".*bb.*"); if(boost::regex_match("aabbcc", regex_bb01)) std::cout<<"the regex_bb01 matched\n"; else std::cout<<"the regex_bb01 not matched\n"; if(boost::regex_match("aabbcc", regex_bb02)) std::cout<<"the regex_bb02 matched\n"; else std::cout<<"the regex_bb02 not matched\n"; if(boost::regex_match("aabbcc", regex_bb03)) std::cout<<"the regex_bb03 matched\n"; else std::cout<<"the regex_bb03 not matched\n"; if(boost::regex_match("aabbcc", regex_bb04)) std::cout<<"the regex_bb04 matched\n"; else std::cout<<"the regex_bb04 not matched\n"; }
the result looks this:
[root@localhost boostcase]# ./regex_test
the regex_bb01 not matched
the regex_bb02 not matched
the regex_bb03 not matched
the regex_bb04 matched
from boost documentation function regex_match
the algorithm regex_match determines whether given regular expression matches all of given character sequence denoted pair of bidirectional-iterators, algorithm defined follows, main use of function data input validation.
in case want use 'bb' match, need use boost::regex_search instead
Comments
Post a Comment