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

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


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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
A slight variation:

#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("tour|tournament|tourn", g);
    const char str[] = "tournament";
    cmatch m;
    if (regex_search(str, m, re))
      cout << m[0] << endl;
    else
      cout << "-" << endl;
  }
}

ECMAscript should match "tour", the POSIX ERE grammars should match
"tournament"

Instead we match "tourn" for all grammars.



More information about the Gcc-bugs mailing list