std::sub_match<BidirIt>:: operator string_type, std::sub_match<BidirIt>:: str
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Regular expressions library
| Classes | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Algorithms | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Iterators | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Exceptions | ||||
|
(C++11)
|
||||
| Traits | ||||
|
(C++11)
|
||||
| Constants | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Regex Grammar | ||||
|
(C++11)
|
std::sub_match
| Member functions | ||||
|
sub_match::str
sub_match::operator string_type
|
||||
| Non-member functions | ||||
|
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(C++20)
|
||||
|
operator string_type
(
)
const
;
|
(1) | |
|
string_type str
(
)
const
;
|
(2) | |
转换为底层 std::basic_string 类型的对象。
1)
隐式转换。
2)
显式转换。
返回值
作为底层
std::basic_string
类型的匹配字符序列对象。若
matched
成员为
false
,则返回空字符串。
复杂度
与底层字符序列的长度呈线性关系。
示例
运行此代码
#include <cassert> #include <iostream> #include <regex> #include <string> int main() { const std::string html{R"("<a href="https://cppreference.net/">)"}; const std::regex re{"(http|https|ftp)://([a-z]+)\\.([a-z]{3})"}; std::smatch parts; std::regex_search(html, parts, re); for (std::ssub_match const& sub : parts) { const std::string s = sub; // (1) 隐式转换 assert(s == sub.str()); // (2) std::cout << s << '\n'; } }
输出:
https://cppreference.net https cppreference com