3

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?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

1 Answers1

14

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

static const boost::regex bad_words("...your regex...", boost::regex::icase);
Ferruccio
  • 98,941
  • 38
  • 226
  • 299