boostorg / boostorg/regex

Difference in regex_replace Replacement Format Handling Between Boost.Regex and std::regex

Open
#210 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
119
Forks
113
PR merge metrics
No merged PRs in 30d

Description

There is a difference in how the replacement format string is handled by regex_replace in Boost.Regex and std::regex.

Consider the following example:

```cpp
#include
#include
#include

int main() {
std::string s{"a:b:c"};
std::string rx{":"};
std::string r{"\\$&"};

// Using std::regex
std::string result_std = std::regex_replace(s, std::regex(rx), r);
std::cout << "std::regex result: " << result_std << std::endl; // Outputs "a\:b\:c"

// Using Boost.Regex
std::string result_boost = boost::regex_replace(s, boost::regex(rx), r);
std::cout << "Boost.Regex result: " << result_boost << std::endl; // Outputs "a$&b$&c"

return 0;
}
```

Affects Boost.Regex 1.84. I didn't try other versions.

Tested with GCC 13.2, clang 18.10 , cl 19.39.33523 and results are the same. Not tested with other versions.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.