[Bug libstdc++/61424] New: std::regex matches right to left, not leftmost longest

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 5 20:11:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61424

            Bug ID: 61424
           Summary: std::regex matches right to left, not leftmost longest
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org

#include <regex>
#include <iostream>

using namespace std;

int main()
{
  regex_constants::syntax_option_type grammar[] = {
    regex_constants::ECMAScript, regex_constants::extended,
    regex_constants::awk, regex_constants::egrep
  };
  for (auto g : grammar)
  {
    regex re("tournament|tour", g);
    const char str[] = "tournament";
    cmatch m;
    regex_search(str, m, re);
    cout << m[0] << endl;
  }
}

This prints:

tour
tour
tour
tour

ECMAscript should check alternations left to right, and POSIX has the leftmost,
longest rule
(http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/leftmost_longest_rule.html)



More information about the Gcc-bugs mailing list