Skip to content

[libc++] std::regex $ alone with match_default doesn't match [last, last)  #75042

@zufuliu

Description

@zufuliu
#include <string>
#include <regex>
#include <iostream>
using namespace std;

int main() {
    string s = "ab";
    regex re("$");
    cout << "$" << endl;
    cout << regex_search(s, re, regex_constants::match_default) << endl;
    cout << regex_search(s, re, regex_constants::match_not_eol) << endl;
    return 0;
}

llvm-mingw 17.0.6:

D:\notepad2>clang++ -std=c++17 -Wall -Wextra test2.cpp

D:\notepad2>a.exe
$
0
0

GCC 13.2.0:

D:\notepad2>g++ -std=c++17 -Wall -Wextra test2.cpp

D:\notepad2>a.exe
$
1
0

MSVC 2022:

D:\notepad2>cl /nologo /EHsc /std:c++17 /W4 test2.cpp
test2.cpp

D:\notepad2>test2.exe
$
1
0

NOTE(ldionne): The first time an attempt was made to fix this, the following happened: #77256 (comment). Any fix for this issue should ensure not to break this use case:

#include <regex>
#include <string>

int main() {
  std::string t = "a";
  std::regex re {"^b*$"};
  std::smatch matches;
  return std::regex_search(t, matches, re);
}

Metadata

Metadata

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.regexIssues related to regex

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions