1、这几天,使用c++的regex库写字符串处理程序,编译时出现:

ary support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
regex_std1.cpp: In function ‘int main(int, char**)’:
regex_std1.cpp:8:2: error: ‘regex’ is not a member of ‘std’
……

根据提示使用:

g++ regex_std1.cpp -std=c++0x或

g++ regex_std1.cpp -std=c++11或

g++ regex_std1.cpp -std=gnu++11

进行编译可通过。

2、regex_match与regex_search的一个区别

两者的匹配要求是不一样的,前者需要整个字符串符合正则表达式才返回真,而后者只需要字符串的一部分符合正则表达式即可返回真,

所以注意下面这个匹配,将返回假:

std::regex reg("wang");

std::string s("hello, wang");

regex_match(s, reg); // 返回flase

而,下面返回真:

std::regex reg("wang");

std::string s("hello, wang");

std::smatch sm;  //match_results类, 可选参数

regex_search(s, sm , reg); // 返回真

详情可见:http://blog.csdn.net/helonsy/article/details/6800790

posted on 2015-08-26 09:46  Namlike  阅读(1682)  评论(0编辑  收藏  举报