【发布时间】:2017-08-28 04:03:56
【问题描述】:
我的任务是用 std::regex 替换 boost::regex,并遇到了 boost::regex 引用以捕获组索引的问题。
正则表达式如下所示:
re = "(^Match1$)|(^Match2$)|(^Match3$)|(^Match4$)"
使用替换字符串:
replace_str = "(?{1}M1)(?{2}M2)(?{3}M3)(?{4}M4)"
如果我打电话给boost::regex_replace("Match1", re, replace_str, format_all)
我得到“M1”作为结果,std::regex_replace("Match1", re, replace_str) 结果由整个 replace_str 组成。
正则表达式的标准化变体没有 format_all 选项(不确定这是否是问题所在)。 http://en.cppreference.com/w/cpp/regex/match_flag_type
如何使用 c++11/14 正则表达式库重现类似的行为? 我是否错过了允许在没有提升的情况下使用该行为的选项或语法?
【问题讨论】: