Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
josuegomes opened this issue Apr 20, 2024 · 0 comments

Comments

@josuegomes
Copy link

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:

#include <iostream>
#include <regex>
#include <boost/regex.hpp>

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant