參考

公共成員函式
(正則表示式)

std::match_results::begin

const_iterator begin() const;
返回指向開始的迭代器
返回一個指向 match_results 物件中第一個匹配項的迭代器。與 match_results::end 一起,這些函式描述了一個範圍,該範圍包含 match_results 物件中的所有匹配項。

請注意,如果表示式匹配,則範圍中的第一個匹配項始終表示整個匹配的字元序列。如果 regex 物件中明確請求了,則範圍中的後續匹配項表示單個子表示式。

如果 match_results 物件是 的(即,表示式不匹配),則返回的值開始end 返回的值相同,表示一個空範圍,並且不應被解引用。

如果 match_results 物件未 就緒,則此函式返回的值可能與 end 的值無關,因此不應用於指定範圍。它也不應被解引用。

引數



返回值

指向 sub_match 物件的迭代器,該物件描述了 match_results 物件中的第一個匹配項。

成員型別常量迭代器(與成員型別相同迭代器)是一個 前向迭代器 型別。
match_results 物件中包含的匹配項始終為常量。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// match_results::begin/end
// - using smatch, a standard alias of match_results<string::iterator>
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string s ("subject");
  std::smatch m;
  std::regex e ("(sub)(.*)");

  std::regex_match ( s, m, e );

  std::cout << "matches:" << std::endl;
  for (std::smatch::iterator it = m.begin(); it!=m.end(); ++it) {
	std::cout << *it << std::endl;
  }
  return 0;
}

輸出
matches:
subject
sub
ject



另見