c++ - 如何使用非捕获组在标记之间用 std::regex_replace 替换空格?
问题描述
我正在尝试使用正则表达式消除字符串中的空格。从以下代码段:
std::string in = "abc> <def\n"
"xyz> \n";
std::regex re = R"((?:>)\s+(?:<)|\s+$)";
std::string out = std::regex_replace(in, re, "(newcontent)");
我期待out
包含
abc>(newcontent)<def
xyz>(newcontent)
但是,唉,我明白了
abc(newcontent)def
xyz>(newcontent)
反而。对我来说,非捕获序列似乎(?:...)
不起作用。我试图用扩展名std::regex re ("....", std::regex::ECMAScript | std::regex::nosubs);
和附加, std::regex_constants::format_default
来修改程序regex_replace
无济于事。这可能是库实现问题还是我有错?
解决方案
推荐阅读
- jquery - 如何在播出日期选择器日历中突出显示当前周
- c# - UWP:找不到类型或命名空间名称“TensorFloat”
- javascript - 多个文件上的打字稿命名空间
- python - 如何在 3dsMax 中实现相机平移?
- json - Spring Web Socket Session 抛出 Jackson 异常
- node.js - 如何在 SAP Cloud Platform 中使用 NodeJS 的 Destination
- android - android中的自定义组项目recyclerview
- android - Android HTTP 请求失败
- ncurses - ncurses:如何刷新单个面板
- oracle - Sharepoint webpart 2016 和 oracle db 9i