regex_match 関数
正規表現と完全に一致しているかどうかを調べます。
template<class BidIt, class Alloc, class Elem, class RXtraits, class Alloc2>
bool regex_match(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_match(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_match(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_match(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_match(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_match(const basic_string<Elem, IOtraits, IOalloc>& str,
const basic_regex<Elem, RXtraits, Alloc2>& re,
match_flag_type flags = match_default);
パラメーター
BidIt
サブマッチの反復子の型。Alloc
一致した結果のアロケーター クラス。Elem
一致させる要素の型。RXtraits
要素の特徴 (traits) クラス。Alloc2
正規表現のアロケーター クラス。IOtraits
文字列の特徴 (traits) クラス。IOalloc
文字列のアロケーター クラス。flags
一致のフラグ。first
一致させるシーケンスの最初。last
一致させるシーケンスの最後。match
一致した結果。ptr
一致させるシーケンスの先頭を指すポインター。re
一致させる正規表現。str
一致させる文字列。
解説
各テンプレート関数は、そのオペランド シーケンスが、対応する正規表現の引数 re と完全に一致した場合にのみ、true を返します。match_results オブジェクトを受け取る関数では、そのメンバーに、検索に成功したかどうかの結果、および、成功した場合には、キャプチャされた正規表現のキャプチャ グループが設定されます。
使用例
// std_tr1__regex__regex_match.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
int main()
{
const char *first = "abc";
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 << "match(f, f+1, \"abc\") == " << std::boolalpha
<< regex_match(first, first + 1, rx, fl) << std::endl;
std::cout << "match(f, l, \"abc\") == " << std::boolalpha
<< regex_match(first, last, mr, rx) << std::endl;
std::cout << " matched: \"" << mr.str() << "\"" << std::endl;
std::cout << "match(\"a\", \"abc\") == " << std::boolalpha
<< regex_match("a", rx) << std::endl;
std::cout << "match(\"abc\", \"abc\") == " << std::boolalpha
<< regex_match("abc", mr, rx) << std::endl;
std::cout << " matched: \"" << mr.str() << "\"" << std::endl;
std::cout << "match(string, \"abc\") == " << std::boolalpha
<< regex_match(std::string("a"), rx) << std::endl;
std::string str("abc");
std::match_results<std::string::const_iterator> mr2;
std::cout << "match(string, \"abc\") == " << std::boolalpha
<< regex_match(str, mr2, rx) << std::endl;
std::cout << " matched: \"" << mr2.str() << "\"" << std::endl;
return (0);
}
必要条件
ヘッダー : <regex>
名前空間: std