[libcxx-commits] [libcxx] [libc++] Fix `regex_search` to match `$` alone with `match_default` flag (PR #78845)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jan 20 06:20:21 PST 2024
================
@@ -47,5 +47,33 @@ int main(int, char**)
assert( std::regex_search(target, re, std::regex_constants::match_not_eol));
}
+ {
+ std::string target = "foo";
+ std::regex re("$");
+ assert(std::regex_search(target, re));
+ assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));
+
+ std::smatch match;
+ assert(std::regex_search(target, match, re));
+ assert(match.position(0) == 3);
+ assert(match.length(0) == 0);
+ assert(!std::regex_search(target, match, re, std::regex_constants::match_not_eol));
+ assert(match.length(0) == 0);
+ }
+
+ {
+ std::string target = "foo";
+ std::regex re("$");
+ assert(!std::regex_match(target, re));
+ assert(!std::regex_match(target, re, std::regex_constants::match_not_eol));
+ }
+
+ {
+ std::string target = "a";
+ std::regex re{"^b*$"};
----------------
H-G-Hristov wrote:
```suggestion
std::regex re("^b*$");
```
Did you test in C++03 mode?
https://github.com/llvm/llvm-project/pull/78845
More information about the libcxx-commits
mailing list