std::regex_iterator<BidirIt,CharT,Traits>:: regex_iterator
|
regex_iterator
(
)
;
|
(1) | (自 C++11 起) |
|
regex_iterator
(
BidirIt a, BidirIt b,
const
regex_type
&
re,
|
(2) | (自 C++11 起) |
|
regex_iterator
(
const
regex_iterator
&
)
;
|
(3) | (自 C++11 起) |
|
regex_iterator
(
BidirIt, BidirIt,
const
regex_type
&&
,
|
(4) | (自 C++11 起) |
构造一个新的
regex_iterator
:
[
a
,
b
)
、正则表达式
re
以及控制匹配行为的标志
m
构造一个
regex_iterator
。该构造函数会使用这些数据执行对
std::regex_search
的初始调用。如果此初始调用的结果为
false
,则
*
this
将被设为序列结束迭代器。
regex_iterator
。
参数
| a | - | 指向目标字符序列起始位置的 LegacyBidirectionalIterator |
| b | - | 指向目标字符序列结束位置的 LegacyBidirectionalIterator |
| re | - | 用于搜索目标字符序列的正则表达式 |
| m | - | 控制 re 行为的标志位 |
示例
#include <iostream> #include <regex> #include <string_view> int main() { constexpr std::string_view str{R"( #ONE: *p = &Mass; #Two: MOV %rd, 42 )"}; const std::regex re("[a-w]"); // 创建 regex_iterator,重载版本 (2) auto it = std::regex_iterator<std::string_view::iterator> { str.cbegin(), str.cend(), re // re 是左值;如果使用立即表达式 // 例如 std::regex{"[a-z]"},这将 // 产生错误,因为重载版本 (4) 已被删除 }; for (decltype(it) last /* 重载版本 (1) */; it != last; ++it) std::cout << (*it).str(); std::cout << '\n'; }
输出:
password
缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 适用范围 | 发布时行为 | 正确行为 |
|---|---|---|---|
| LWG 2332 | C++11 |
由临时
basic_regex
构造的
regex_iterator
会立即失效 |
通过已删除的重载禁止此类构造 |