Tom*_*ica 3 c++ case-insensitive boost-regex
奇怪的是,谷歌拒绝回答这样一个简单的问题:
我如何使boost :: regexp不区分大小写?
这就是我所拥有的:
static const boost::regex bad_words("(?:^|.* )(f(?:uc|a)k(?:i[ng]{1,2})?|bitch(?:es|iz)?)(?:$| .*)"); //reduced to the english ones
Run Code Online (Sandbox Code Playgroud)
当然,我也希望过滤大写的坏词.这就是我匹配它们的方式:
//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
}
Run Code Online (Sandbox Code Playgroud)
那么,对于不敏感的正则表达式还有另一个函数吗?还是另一个正则表达式对象?或修改器i可用?
Fer*_*cio 13
您可以使用以下boost::regex::icase选项:
static const boost::regex bad_words("...your regex...", boost::regex::icase);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4936 次 |
| 最近记录: |