2013-03-25 130 views
1

奇怪的是,谷歌拒绝回答这样一个简单的问题:
如何使boost :: regexp不区分大小写?忽略大小写boost :: regexp

这是我有:

static const boost::regex bad_words("(?:^|.*)(f(?:uc|a)k(?:i[ng]{1,2})?|bitch(?:es|iz)?)(?:$| .*)"); //reduced to the english ones 

当然,我要过滤大写不好的话为好。这是我如何匹配他们:

//std::string ms; - chat messsage 
//boost::match_results<std::string::const_iterator> results; - prewious regexp results 
else if(boost::regex_match(ms, results2, bad_words)) { // 
     std::stringstream msg; 
     msg<<"Avoid bad words! Word '"<<results2[1]<<"' is banned!"; 
     this->whisper(results[1], msg.str()); //name, message 
} 

那么,是否有另一个不敏感的正则表达式的函数?或另一个正则表达式对象?或者修饰符i可用?

回答

8

可以使用boost::regex::icase选项:

static const boost::regex bad_words("...your regex...", boost::regex::icase);