[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的文档吧。