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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -