正则表达式对象,封装编译后的模式,提供匹配、搜索、替换等功能。
More...
#include <re.h>
|
| | Regex (const std::string &pat, std::regex::flag_type flags=std::regex::ECMAScript) |
| | 构造一个 Regex 对象。
|
| Match | search (const std::string &text) const |
| | 在文本中搜索第一个匹配。
|
| Match | match (const std::string &text) const |
| | 尝试从文本开头匹配整个模式。
|
| Match | fullmatch (const std::string &text) const |
| | match 的别名,与 Python 的 re.fullmatch 语义相同。
|
| std::vector< std::string > | findall (const std::string &text) const |
| | 查找所有不重叠的匹配,返回匹配字符串列表。
|
| IteratorPair | finditer (const std::string &text) const |
| | 返回一个可迭代对象,遍历所有匹配的 Match 对象。
|
| std::vector< std::string > | split (const std::string &text, int maxsplit=0) const |
| | 使用正则表达式分割字符串。
|
| std::string | sub (const std::string &repl, const std::string &text, int count=0) const |
| | 替换匹配的子串(最多 count 次)。
|
| std::pair< std::string, int > | subn (const std::string &repl, const std::string &text, int count=0) const |
| | 替换匹配的子串并返回替换次数。
|
正则表达式对象,封装编译后的模式,提供匹配、搜索、替换等功能。
该类类似于 Python 的 re.compile 返回的对象,支持链式操作。
◆ Regex()
| console::Regex::Regex |
( |
const std::string & | pat, |
|
|
std::regex::flag_type | flags = std::regex::ECMAScript ) |
|
inline |
构造一个 Regex 对象。
- Parameters
-
| pat | 正则表达式字符串。 |
| flags | 语法标志,默认为 ECMAScript。 |
◆ findall()
| std::vector< std::string > console::Regex::findall |
( |
const std::string & | text | ) |
const |
|
inline |
查找所有不重叠的匹配,返回匹配字符串列表。
- Parameters
-
- Returns
- std::vector<std::string> 所有匹配的字符串。
◆ finditer()
| IteratorPair console::Regex::finditer |
( |
const std::string & | text | ) |
const |
|
inline |
◆ fullmatch()
| Match console::Regex::fullmatch |
( |
const std::string & | text | ) |
const |
|
inline |
match 的别名,与 Python 的 re.fullmatch 语义相同。
- Parameters
-
- Returns
- Match 匹配结果对象。
◆ match()
| Match console::Regex::match |
( |
const std::string & | text | ) |
const |
|
inline |
尝试从文本开头匹配整个模式。
- Parameters
-
- Returns
- Match 匹配结果对象。
◆ search()
| Match console::Regex::search |
( |
const std::string & | text | ) |
const |
|
inline |
在文本中搜索第一个匹配。
- Parameters
-
- Returns
- Match 匹配结果对象。
◆ split()
| std::vector< std::string > console::Regex::split |
( |
const std::string & | text, |
|
|
int | maxsplit = 0 ) const |
|
inline |
使用正则表达式分割字符串。
- Parameters
-
| text | 要分割的字符串。 |
| maxsplit | 最大分割次数,0 表示不限。 |
- Returns
- std::vector<std::string> 分割后的子串列表。
◆ sub()
| std::string console::Regex::sub |
( |
const std::string & | repl, |
|
|
const std::string & | text, |
|
|
int | count = 0 ) const |
|
inline |
替换匹配的子串(最多 count 次)。
- Parameters
-
| repl | 替换字符串。 |
| text | 原始文本。 |
| count | 最大替换次数,0 表示替换所有。 |
- Returns
- std::string 替换后的字符串。
◆ subn()
| std::pair< std::string, int > console::Regex::subn |
( |
const std::string & | repl, |
|
|
const std::string & | text, |
|
|
int | count = 0 ) const |
|
inline |
替换匹配的子串并返回替换次数。
- Parameters
-
| repl | 替换字符串。 |
| text | 原始文本。 |
| count | 最大替换次数,0 表示替换所有。 |
- Returns
- std::pair<std::string, int> (新字符串, 替换次数)。
The documentation for this class was generated from the following file: