<regex>
運算子
operator!=
operator>
operator>=
operator<
operator<<
operator<=
operator==
operator!=
不同物件的不等於比較。
template <class BidIt>
bool operator!=(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator!=(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator!=(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator!=(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator!=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator!=(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator!=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
template <class BidIt, class Alloc>
bool operator!=(const match_results<BidIt, Alloc>& left,
const match_results<BidIt, Alloc>& right);
參數
BidIt
迭代器類型。
IOtraits
字串特性類別。
Alloc
配置器類別。
left
要比較的左側物件。
right
要比較的右側物件。
備註
每個範本運算子會傳回 !(left == right)
。
範例
// std__regex__operator_ne.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "match == " << mr.str() << std::endl;
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "match != match == " << std::boolalpha
<< (mr != mr) << std::endl;
std::cout << "sub != sub == " << std::boolalpha
<< (sub != sub) << std::endl;
std::cout << "string(\"aab\") != sub == " << std::boolalpha
<< (Mystr("aab") != sub) << std::endl;
std::cout << "sub != string(\"aab\") == " << std::boolalpha
<< (sub != Mystr("aab")) << std::endl;
std::cout << "\"aab\" != sub == " << std::boolalpha
<< ("aab" != sub) << std::endl;
std::cout << "sub != \"aab\" == " << std::boolalpha
<< (sub != "aab") << std::endl;
std::cout << "'a' != sub == " << std::boolalpha
<< ('a' != sub) << std::endl;
std::cout << "sub != 'a' == " << std::boolalpha
<< (sub != 'a') << std::endl;
return (0);
}
match == caaa
sub == aaa
match != match == false
sub != sub == false
string("aab") != sub == true
sub != string("aab") == true
"aab" != sub == true
sub != "aab" == true
'a' != sub == true
sub != 'a' == true
operator<
不同物件的小於比較。
template <class BidIt>
bool operator<(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator<(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator<(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator<(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator<(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator<(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator<(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
參數
BidIt
迭代器類型。
IOtraits
字串特性類別。
Alloc
配置器類別。
left
要比較的左側物件。
right
要比較的右側物件。
備註
每個樣板運算子都會將其自變數轉換成字串類型,而且只有在左邊的轉換值比較小於右轉換的值時,才會傳回 true。
範例
// std__regex__operator_lt.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "sub < sub == " << std::boolalpha
<< (sub < sub) << std::endl;
std::cout << "string(\"aab\") < sub == " << std::boolalpha
<< (Mystr("aab") < sub) << std::endl;
std::cout << "sub < string(\"aab\") == " << std::boolalpha
<< (sub < Mystr("aab")) << std::endl;
std::cout << "\"aab\" < sub == " << std::boolalpha
<< ("aab" < sub) << std::endl;
std::cout << "sub < \"aab\" == " << std::boolalpha
<< (sub < "aab") << std::endl;
std::cout << "'a' < sub == " << std::boolalpha
<< ('a' < sub) << std::endl;
std::cout << "sub < 'a' == " << std::boolalpha
<< (sub < 'a') << std::endl;
return (0);
}
sub == aaa
sub < sub == false
string("aab") < sub == false
sub < string("aab") == true
"aab" < sub == false
sub < "aab" == true
'a' < sub == true
sub < 'a' == false
operator<<
在資料流中插入 sub_match。
template <class Elem, class IOtraits, class Alloc, class BidIt>
basic_ostream<Elem, IOtraits>& operator<<(basic_ostream<Elem, IOtraits>& os,
const sub_match<BidIt>& right);
參數
Elem
元素類型。
IOtraits
字串特性類別。
Alloc
配置器類別。
BidIt
迭代器類型。
操作系統
輸出資料流。
right
要插入的 物件。
備註
範本運算子會傳回 os << right.str()
。
範例
// std__regex__operator_ins.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[0];
std::cout << "whole match: " << sub << std::endl;
return (0);
}
whole match: caaa
operator<=
不同物件的小於或等於比較。
template <class BidIt>
bool operator<=(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator<=(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator<=(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator<=(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator<=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator<=(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator<=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
參數
BidIt
迭代器類型。
IOtraits
字串特性類別。
Alloc
配置器類別。
left
要比較的左側物件。
right
要比較的右側物件。
備註
每個範本運算子會傳回 !(right < left)
。
範例
// std__regex__operator_le.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "sub <= sub == " << std::boolalpha
<< (sub <= sub) << std::endl;
std::cout << "string(\"aab\") <= sub == " << std::boolalpha
<< (Mystr("aab") <= sub) << std::endl;
std::cout << "sub <= string(\"aab\") == " << std::boolalpha
<< (sub <= Mystr("aab")) << std::endl;
std::cout << "\"aab\" <= sub == " << std::boolalpha
<< ("aab" <= sub) << std::endl;
std::cout << "sub <= \"aab\" == " << std::boolalpha
<< (sub <= "aab") << std::endl;
std::cout << "'a' <= sub == " << std::boolalpha
<< ('a' <= sub) << std::endl;
std::cout << "sub <= 'a' == " << std::boolalpha
<< (sub <= 'a') << std::endl;
return (0);
}
sub == aaa
sub <= sub == true
string("aab") <= sub == false
sub <= string("aab") == true
"aab" <= sub == false
sub <= "aab" == true
'a' <= sub == true
sub <= 'a' == false
operator==
不同物件的等於比較。
template <class BidIt>
bool operator==(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator==(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator==(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator==(const typename iterator_traits<BidIt>::value_type* left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator==(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type* right);
template <class BidIt>
bool operator==(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator==(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
template <class BidIt, class Alloc>
bool operator==(const match_results<BidIt, Alloc>& left,
const match_results<BidIt, Alloc>& right);
參數
BidIt
迭代器類型。
IOtraits
字串特性類別。
Alloc
配置器類別。
left
要比較的左側物件。
right
要比較的右側物件。
備註
每個範本運算子都會將它的每個引數轉換為字串類型,並傳回比較已轉換物件之後相等的結果。
當範本運算子將其引數轉換為字串類型之後,它會使用下列第一個適用的轉換:
自變數,其型別為類別範本 match_results
的特製化,或 sub_match
藉由呼叫 str
成員函式來轉換;
類型為類別範本 basic_string
特製化的自變數不會變更;
所有其他自變數類型都會藉由將自變數值傳遞至建構函式,以取得類別範本 basic_string
的適當特製化。
範例
// std__regex__operator_eq.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "match == " << mr.str() << std::endl;
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "match == match == " << std::boolalpha
<< (mr == mr) << std::endl;
std::cout << "sub == sub == " << std::boolalpha
<< (sub == sub) << std::endl;
std::cout << "string(\"aab\") == sub == " << std::boolalpha
<< (Mystr("aab") == sub) << std::endl;
std::cout << "sub == string(\"aab\") == " << std::boolalpha
<< (sub == Mystr("aab")) << std::endl;
std::cout << "\"aab\" == sub == " << std::boolalpha
<< ("aab" == sub) << std::endl;
std::cout << "sub == \"aab\" == " << std::boolalpha
<< (sub == "aab") << std::endl;
std::cout << "'a' == sub == " << std::boolalpha
<< ('a' == sub) << std::endl;
std::cout << "sub == 'a' == " << std::boolalpha
<< (sub == 'a') << std::endl;
return (0);
}
match == caaa
sub == aaa
match == match == true
sub == sub == true
string("aab") == sub == false
sub == string("aab") == false
"aab" == sub == false
sub == "aab" == false
'a' == sub == false
sub == 'a' == false
operator>
不同物件的大於比較。
template <class BidIt>
bool operator>(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator>(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator>(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator>(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator>(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator>(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator>(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
參數
BidIt
迭代器類型。
IOtraits
字串特性類別。
Alloc
配置器類別。
left
要比較的左側物件。
right
要比較的右側物件。
備註
每個範本運算子會傳回 right < left
。
範例
// std__regex__operator_gt.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "sub > sub == " << std::boolalpha
<< (sub > sub) << std::endl;
std::cout << "string(\"aab\") > sub == " << std::boolalpha
<< (Mystr("aab") > sub) << std::endl;
std::cout << "sub > string(\"aab\") == " << std::boolalpha
<< (sub > Mystr("aab")) << std::endl;
std::cout << "\"aab\" > sub == " << std::boolalpha
<< ("aab" > sub) << std::endl;
std::cout << "sub > \"aab\" == " << std::boolalpha
<< (sub > "aab") << std::endl;
std::cout << "'a' > sub == " << std::boolalpha
<< ('a' > sub) << std::endl;
std::cout << "sub > 'a' == " << std::boolalpha
<< (sub > 'a') << std::endl;
return (0);
}
sub == aaa
sub > sub == false
string("aab") > sub == true
sub > string("aab") == false
"aab" > sub == true
sub > "aab" == false
'a' > sub == false
sub > 'a' == true
operator>=
不同物件的大於或等於比較。
template <class BidIt>
bool operator>=(const sub_match<BidIt>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator>=(
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
const sub_match<BidIt>& right);
template <class BidIt, class IOtraits, class Alloc>
bool operator>=(const sub_match<BidIt>& left,
const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template <class BidIt>
bool operator>=(const typename iterator_traits<BidIt>::value_type *left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator>=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type *right);
template <class BidIt>
bool operator>=(const typename iterator_traits<BidIt>::value_type& left,
const sub_match<BidIt>& right);
template <class BidIt>
bool operator>=(const sub_match<BidIt>& left,
const typename iterator_traits<BidIt>::value_type& right);
參數
BidIt
迭代器類型。
IOtraits
字串特性類別。
Alloc
配置器類別。
left
要比較的左側物件。
right
要比較的右側物件。
備註
每個範本運算子會傳回 !(left < right)
。
範例
// std__regex__operator_ge.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::cmatch::string_type Mystr;
int main()
{
std::regex rx("c(a*)|(b)");
std::cmatch mr;
std::regex_search("xcaaay", mr, rx);
std::csub_match sub = mr[1];
std::cout << "sub == " << sub << std::endl;
std::cout << std::endl;
std::cout << "sub >= sub == " << std::boolalpha
<< (sub >= sub) << std::endl;
std::cout << "string(\"aab\") >= sub == " << std::boolalpha
<< (Mystr("aab") >= sub) << std::endl;
std::cout << "sub >= string(\"aab\") == " << std::boolalpha
<< (sub >= Mystr("aab")) << std::endl;
std::cout << "\"aab\" >= sub == " << std::boolalpha
<< ("aab" >= sub) << std::endl;
std::cout << "sub >= \"aab\" == " << std::boolalpha
<< (sub >= "aab") << std::endl;
std::cout << "'a' >= sub == " << std::boolalpha
<< ('a' >= sub) << std::endl;
std::cout << "sub >= 'a' == " << std::boolalpha
<< (sub >= 'a') << std::endl;
return (0);
}
sub == aaa
sub >= sub == true
string("aab") >= sub == true
sub >= string("aab") == false
"aab" >= sub == true
sub >= "aab" == false
'a' >= sub == false
sub >= 'a' == true
另請參閱
<regex>
regex_constants 類別
regex_error 類別
<regex> 函式
regex_iterator 類別
regex_token_iterator 類別
regex_traits 類別
<regex> typedefs