C++ regex not understanding -
the following outputs ">hut" expect output "hut". know .* greedy > must matched , outside of capture group why in submatch?
#include <string> #include <regex> #include <iostream> using namespace std; int main() { regex my_r(".*>(.*)"); string temp(r"~(cols="64">hut)~"); smatch m; if (regex_match(temp, m, my_r)) { cout << m[1] << endl; } }
this bug in libstdc++'s implementation. watch these:
#include <string> #include <regex> #include <boost/regex.hpp> #include <iostream> int main() { { using namespace std; regex my_r("(.*)(6)(.*)"); smatch m; if (regex_match(std::string{"123456789"}, m, my_r)) { std::cout << m.length(1) << ", " << m.length(2) << ", " << m.length(3) << std::endl; } } { using namespace boost; regex my_r("(.*)(6)(.*)"); smatch m; if (regex_match(std::string{"123456789"}, m, my_r)) { std::cout << m.length(1) << ", " << m.length(2) << ", " << m.length(3) << std::endl; } } return 0; } if compile gcc, first 1 (libstdc++) returns totally wrong result 9, -2, 4 , second 1 (boost's implementation) returns 5, 1, 3 expected.
if compile clang + libc++, code works fine.
(note libstdc++'s regex implementation "partially supported", described in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52719.)
Comments
Post a Comment