regex_search 函式
搜尋規則運算式相符項目。
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
相符的 Iterator 型別。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