相关疑难解决方法(0)

正则表达式替换为c ++ 11中的回调?

是否有正则表达式替换函数将匹配发送到用户函数,然后替换返回值:

我尝试过这种方法,但显然不起作用:

cout << regex_replace("my values are 9, 19", regex("\d+"), my_callback);
Run Code Online (Sandbox Code Playgroud)

和功能:

std::string my_callback(std::string &m) {
  int int_m = atoi(m.c_str());
  return std::to_string(int_m + 1);
}
Run Code Online (Sandbox Code Playgroud)

结果应该是: my values are 10, 20

我的意思是类似于php preg_replace_callback或python的工作模式re.sub(pattern, callback, subject)

我的意思是最新的4.9 gcc,能够正常运行而无需提升.

c++ regex callback c++11

18
推荐指数
2
解决办法
3075
查看次数

GCC中的C++ 0x正则表达式

以下代码:

#include <regex>
using namespace std;

(snippage)

regex_search(s, m, re);
Run Code Online (Sandbox Code Playgroud)

适用于Microsoft C++,但GCC 4.4.3提供以下错误消息:

/usr/include/c++/4.4/tr1_impl/regex:2255:警告:内联函数'bool std :: regex_search(_Bi_iter,_Bi_iter,std :: match_results <_Bi_iter,_Allocator>&,const std :: basic_regex <_Ch_type,_Rx_traits >&,std :: regex_constants :: match_flag_type)[与_Bi_iter = __gnu_cxx :: __ normal_iterator,std :: allocator >>,_ Allocator = std :: allocator,std :: allocator >>>,_Ch_type = char,_Rx_traits = std :: regex_traits]'已使用但从未定义过

当然,如果正则表达式只是GCC待办事项列表中的C++ 0x功能之一,我也不会感到惊讶,但在这种情况下,我为什么感到高兴呢?包含指令,变量声明等,并且仅在函数调用上跳过(它甚至似乎理解).

有什么我想念的吗?

regex gcc c++11

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++11 ×2

regex ×2

c++ ×1

callback ×1

gcc ×1