regex_search Function
搜尋符合規則運算式。
template<class BidIt, class Alloc, class Elem, class RXtraits, class Alloc2>
bool regex_search(BidIt first, Bidit last,
match_results<BidIt, Alloc>& match,
const basic_regex<Elem, RXtraits, Alloc2>& re,
match_flag_type flags = match_default);
template<class BidIt, class Elem, class RXtraits, class Alloc2>
bool regex_search(BidIt first, Bidit last,
const basic_regex<Elem, RXtraits, Alloc2>& re,
match_flag_type flags = match_default);
template<class Elem, class Alloc, class RXtraits, class Alloc2>
bool regex_search(const Elem* ptr,
match_results<const Elem*, Alloc>& match,
const basic_regex<Elem, RXtraits, Alloc2>& re,
match_flag_type flags = match_default);
template<class Elem, class RXtraits, class Alloc2>
bool regex_search(const Elem* ptr,
const basic_regex<Elem, RXtraits, Alloc2>& re,
match_flag_type flags = match_default);
template<class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits, class Alloc2>
bool regex_search(const basic_string<Elem, IOtraits, IOalloc>& str,
match_results<typename basic_string<Elem, IOtraits, IOalloc>::const_iterator, Alloc>& match,
const basic_regex<Elem, RXtraits, Alloc2>& re,
match_flag_type flags = match_default);
template<class IOtraits, class IOalloc, class Elem, class RXtraits, class Alloc2>
bool regex_search(const basic_string<Elem, IOtraits, IOalloc>& str,
const basic_regex<Elem, RXtraits, Alloc2>& re,
match_flag_type flags = match_default);
參數
BidIt
子相符項目的列舉值型別。Alloc
比對出現配置器類別。Elem
項目的型別來對應。RXtraits
項目特性類別。Alloc2
規則運算式配置器類別。IOtraits
字串類別特性。IOalloc
字串配置器類別。flags
符合的旗標。first
序列開頭來對應。last
序列結尾來對應。match
符合結果。ptr
要啟動的指標來對應序列。re
要比對的規則運算式。str
符合的字串。
備註
,才會搜尋在其運算元序列的規則運算式引數 re 成功,每一個樣板函式傳回 true。 取得物件的 match_results 函式設定其成員反映搜尋是否成功和,以何種規則運算式的各種擷取群組所擷取的。
範例
// std_tr1__regex__regex_search.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
int main()
{
const char *first = "abcd";
const char *last = first + strlen(first);
std::cmatch mr;
std::regex rx("abc");
std::regex_constants::match_flag_type fl =
std::regex_constants::match_default;
std::cout << "search(f, f+1, \"abc\") == " << std::boolalpha
<< regex_search(first, first + 1, rx, fl) << std::endl;
std::cout << "search(f, l, \"abc\") == " << std::boolalpha
<< regex_search(first, last, mr, rx) << std::endl;
std::cout << " matched: \"" << mr.str() << "\"" << std::endl;
std::cout << "search(\"a\", \"abc\") == " << std::boolalpha
<< regex_search("a", rx) << std::endl;
std::cout << "search(\"xabcd\", \"abc\") == " << std::boolalpha
<< regex_search("xabcd", mr, rx) << std::endl;
std::cout << " matched: \"" << mr.str() << "\"" << std::endl;
std::cout << "search(string, \"abc\") == " << std::boolalpha
<< regex_search(std::string("a"), rx) << std::endl;
std::string str("abcabc");
std::match_results<std::string::const_iterator> mr2;
std::cout << "search(string, \"abc\") == " << std::boolalpha
<< regex_search(str, mr2, rx) << std::endl;
std::cout << " matched: \"" << mr2.str() << "\"" << std::endl;
return (0);
}
需求
標題: <regex>
命名空間: std