c++11 - C++ boost::regex_match strange behaviour -
trying boost::regex_match , got strange behaviour.
boost::cmatch what; std::string fn_re_str = r"(\.sig\|\|([a-za-z0-9$]+)\()"; boost::regex fn_re(fn_re_str); if (boost::regex_match("{var d=a[c];if(d.sig||d.s){var e=d.sig||qt(d.", what, fn_re)) { std::cout << what[1] << std::endl; } else { std::cerr << "not found" << std::endl; } qt expected found.
here https://regex101.com/r/ir9rw5/1 found.
why boost::regex_match can't find it? miss something?
regex_match matches full input: documentation
⚠ important
note result true if expression matches whole of input sequence. if want search expression somewhere within sequence use
regex_search. if want match prefix of character string useregex_searchflagmatch_continuousset
use regex_search
#include <boost/regex.hpp> #include <iostream> int main() { boost::cmatch what; std::string fn_re_str = r"(\.sig\|\|([a-za-z0-9$]+)\()"; boost::regex fn_re(fn_re_str); if (boost::regex_search("{var d=a[c];if(d.sig||d.s){var e=d.sig||qt(d.", what, fn_re)) { std::cout << what[1] << std::endl; } else { std::cerr << "not found" << std::endl; } } prints
qt
Comments
Post a Comment