Вопрос

Strangely enough, google refuses to answer such simple question:
How do I make boost::regexp case-insensitive?

This is what I have:

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

Of course, I want to filter uppercase bad words as well. This is how I match them:

//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
}

So, is there another function for insensitive regexp? Or another regexp object? Or the modifier i is available?

Это было полезно?

Решение

You can use the boost::regex::icase option:

static const boost::regex bad_words("...your regex...", boost::regex::icase);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top