C++11 | 正则表达式(1)介绍了C++11中的正则表达式类库,举了一个迭代器的示例,演示使用regex、sregex_iterator、smatch的用法。这次来看看regex_search的用法。
regex_search方法的原型如下:
//(1)
template< class BidirIt,
class Alloc, class CharT, class Traits >
bool regex_search( BidirIt first, BidirIt last,
std::match_results<BidirIt,Alloc>& m,
const std::basic_regex<CharT,Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default );
//(2)
template< class CharT, class Alloc, class Traits >
bool regex_search( const CharT* str,
std::match_results<const CharT*,Alloc>& m,
const std::basic_regex<CharT,Traits>& e,
std::regex_constants::match_flag_type flags =
std::regex_constants::match_default );
//(3)