首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

[boost_regex]无法匹配解决方案

2012-02-05 
[boost_regex]无法匹配boost::regexre( [^ ])if(boost::regex_match( htmlbody dddd /body

[boost_regex]无法匹配
boost::regex   re( " <[^> ]> ");
if   (boost::regex_match( " <html> <body> dddd </body> </html> ",   re))
{
int   i   =   1;
i++;
i--;  
}

很简单的一个式子,我在GRETA中可以匹配,但是怎么用boost就无法匹配呢
还是说boost的语法不是这样的,我看boost   regex的文档看的都快头晕了
各位帮我分析下

[解决办法]
#include <boost/regex.hpp>
#include <iostream>

bool validate_card_format(const std::string s)
{
static const boost::regex e( " <.+> ");
return regex_match(s, e);
}

int main()
{
std::cout < < (validate_card_format( " <html> <body> dddd </body> </html> ")? "PASS ": "Error ") ; // PASS

system( "pause ");
return 0;
}
[解决办法]
使用 非贪婪匹配, 在+后面使用 ? 即可
[解决办法]
再多看看boost::regex的文档吧。

热点排行