Ignore case using boost::regex_search
Asked Answered
A

2

9

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

Please post an easy example.

Thanks!

Artless answered 6/6, 2011 at 6:1 Comment(0)
E
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);
Enamel answered 6/6, 2011 at 6:32 Comment(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.Fayth
J
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);
Jodijodie answered 7/6, 2016 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.