Console Library 4.7.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
console::Regex::Match Class Reference

匹配结果对象,包含匹配信息。 More...

#include <re.h>

Public Member Functions

 Match ()
 默认构造,表示不成功的匹配。
 Match (const std::smatch &m)
 从 std::smatch 构造。
std::string group (int n=0) const
 获取指定捕获组的内容。
std::vector< std::string > groups () const
 获取所有捕获组(不包括整个匹配)的内容。
int start (int n=0) const
 获取指定捕获组在原始字符串中的起始索引。
int end (int n=0) const
 获取指定捕获组在原始字符串中的结束索引(最后一个字符之后的位置)。
std::pair< int, int > span (int n=0) const
 获取指定捕获组的起始和结束索引组成的 pair。
 operator bool () const
 检查匹配是否成功。

Detailed Description

匹配结果对象,包含匹配信息。

提供访问匹配组、位置索引等功能,类似 Python 的 re.Match 对象。

Constructor & Destructor Documentation

◆ Match() [1/2]

console::Regex::Match::Match ( )
inline

默认构造,表示不成功的匹配。

◆ Match() [2/2]

console::Regex::Match::Match ( const std::smatch & m)
inline

从 std::smatch 构造。

Member Function Documentation

◆ end()

int console::Regex::Match::end ( int n = 0) const
inline

获取指定捕获组在原始字符串中的结束索引(最后一个字符之后的位置)。

Parameters
n组索引,默认为 0。
Returns
int 结束索引,若无效则返回 -1。

◆ group()

std::string console::Regex::Match::group ( int n = 0) const
inline

获取指定捕获组的内容。

Parameters
n组索引(0 表示整个匹配,默认为 0)。若索引无效则返回空字符串。
Returns
std::string 匹配的子串。

◆ groups()

std::vector< std::string > console::Regex::Match::groups ( ) const
inline

获取所有捕获组(不包括整个匹配)的内容。

Returns
std::vector<std::string> 各捕获组的字符串列表。

◆ operator bool()

console::Regex::Match::operator bool ( ) const
inlineexplicit

检查匹配是否成功。

Returns
true 若匹配成功,否则 false。

◆ span()

std::pair< int, int > console::Regex::Match::span ( int n = 0) const
inline

获取指定捕获组的起始和结束索引组成的 pair。

Parameters
n组索引,默认为 0。
Returns
std::pair<int, int> (start, end)。

◆ start()

int console::Regex::Match::start ( int n = 0) const
inline

获取指定捕获组在原始字符串中的起始索引。

Parameters
n组索引,默认为 0。
Returns
int 起始索引,若无效则返回 -1。

The documentation for this class was generated from the following file: