[libcxx-commits] [libcxx] [libc++] Fix `regex_search` to match `$` alone with `match_default` flag (PR #77256)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 15 18:01:22 PST 2024


alexfh wrote:

It looks like the patch changes the behavior of search for patterns anchored both to the start and to the end of the input, e.g. after this change `std::regex_search` finds a pattern like `^b*$` in strings that don't match it (like `"a"`). Is this intended?

The behavior is now different to that of libstdc++: https://gcc.godbolt.org/z/hcd4acrb6

```
#include <regex>
#include <string>

int main() {
  std::string t = "a";
  std::regex re {"^b*$"};
  std::smatch matches;
  return std::regex_search(t, matches, re);
}
```
returns 1 on libc++ and 0 on libstdc++ (and libc++ before this change).

https://github.com/llvm/llvm-project/pull/77256


More information about the libcxx-commits mailing list