9

How do you use boost::regex_search with the ignore case flags or constants in C++?

Please post an easy example.

Thanks!

Ross Rogers
  • 23,523
  • 27
  • 108
  • 164
arturgspb
  • 1,004
  • 1
  • 12
  • 19

2 Answers2

13

You need something like this

boost::regex regex("your expression here", boost::regex::icase);
boost::smatch what;

string mystring;
bool search_result = boost::regex_search(mystring.begin(),mystring.end(), what, regex);
O.C.
  • 6,711
  • 1
  • 25
  • 26
  • 1
    You can omit the "what" parameter (match results) if you don't need it, and you can pass the string itself instead of its iterators. – JWWalker May 15 '15 at 21:59
3

Or something like this (without setting boost::regex::icase):

boost::regex regex("(?i)expression");
boost::smatch what;

string mystring;
bool search_result = boost::regex_search(mystring.begin(),mystring.end(), what, regex);
Dhia
  • 10,119
  • 11
  • 58
  • 69