std::sub_match

定义于头文件 <regex>
template<

    class BidirIt

> class sub_match;
(C++11 起)

正则表达式引擎用类模板 sub_match ,表示有标记子表达式所匹配的字符序列。 匹配是目标范围中匹配正则表达式的 [begin, end) 对,不过拥有附加的观察器函数以增进代码清晰度。

只有默认构造函数是可公开访问的。在处理 regex 算法之一期间, sub_match 的实例作为 std::match_results 容器的一部分正常构造并移居。

成员函数返回定义的默认值,除非 matched 成员为 true

sub_match 继承自 std::pair<BidirIt, BidirIt> ,尽管它不能当做 std::pair 对象,因为成员函数,如交换与赋值,不会按期待工作。

目录

类型要求

-
BidirIt 必须满足 BidirectionalIterator 的要求。

特化

为常见字符类型提供数个特化:

定义于头文件 <regex>
类型 定义
csub_match sub_match<const char*>
wcsub_match sub_match<const wchar_t*>
ssub_match sub_match<std::string::const_iterator>
wssub_match sub_match<std::wstring::const_iterator>

成员类型

成员类型 定义
iterator BidirIt
value_type std::iterator_traits<BidirIt>::value_type
difference_type std::iterator_traits<BidirIt>::difference_type
string_type std::basic_string<value_type>

成员对象

bool matched
指示此匹配是否成功
(公开成员对象)

继承自 std::pair

BidirIt first
匹配序列的开始。
(公开成员对象)
BidirIt second
匹配序列的结尾后一位置。
(公开成员对象)

成员函数

构造匹配对象
(公开成员函数)
观察器
若存在则返回匹配的长度
(公开成员函数)
转换为底层字符串类型
(公开成员函数)
若存在则比较匹配的子序列
(公开成员函数)

非成员函数

比较两个 sub_match 对象
(函数模板)
输出匹配的字符序列
(函数模板)

参阅

在正则表达式子匹配上迭代
(类模板)

版本历史

  • (当前 | 先前 2017年9月28日 (四) 21:29Fruderica讨论 | 贡献 . . (2,759字节) (-3). . (撤销)
  • 当前 | 先前 2017年8月8日 (二) 20:06Fruderica讨论 | 贡献. . (2,762字节) (-1,394). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:16P12bot讨论 | 贡献 . . (4,156字节) (-302). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 11:24P12bot讨论 | 贡献 . . (4,458字节) (+217). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 12:11P12讨论 | 贡献 . . (4,241字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (4,241字节) (-104). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 15:33P12讨论 | 贡献 . . (4,345字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (4,345字节) (+4,345). . (Translated from the English version using Google Translate)