20 Mar
2026
20 Mar
'26
8:33 p.m.
On 20/03/2026 07:29, 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
\n is a regular expression meaning "Match any newline character", which happens to include \r and a few other things as well. If you want to match a literal '\n' then you need to escape it and the appropriate regular expression string is therefore R"\\n" HTH, John.