Re: [Regex] \r matching \n
Seth via Boost <[email protected]>
| Newsgroups | gmane.comp.lib.boost.devel |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Mar 20, 2026, at 8:29 AM, Olaf van der Spek via Boost wrote:
> Hi,
>
> In this regex the \n matches \r. How is this defined / controlled? Is
> there a way to only match \n?
>
> std::string s = "[*] A\rB\n";
> s = boost::regex_replace(s, boost::regex(R"(\[\*\](.+?)(\n|$))"),
> "<li>\\1</li>");
> std::println("{}", js_encode(s)); // <li> A</li>\rB\n
>
> Regards,
To me it appears as if `$` might be behaving like that:
https://godbolt.org/z/s1zaMqT1q
#include <boost/regex.hpp>
#include <fmt/ranges.h>
#include <span>
int main() {
std::string s = "A\rB\n";
s = boost::regex_replace(s, boost::regex(R"((.+?)\n)"),
"<\\1>");
fmt::print("{}\n", std::span(s));
fmt::print("{::#x}\n", std::span(s));
}
Which prints, on my linux box:
['<', 'A', '\r', 'B', '>']
[0x3c, 0x41, 0xd, 0x42, 0x3e]
Of course, there might be some Windows quirk involved.
_______________________________________________
Boost mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/[email protected]/message/AD7UVYFPRYOWAO5BSIWE5ZSBT3QS4UVC/