|
Console Library 8.0.0
A header-only library that makes C++ simple
|
正则表达式对象,封装编译后的模式,提供匹配、搜索、替换等功能。 More...
#include <re.h>
Classes | |
| class | Match |
| 匹配结果对象,保存文本副本和位置信息,不依赖迭代器有效性。 More... | |
Public Types | |
| using | string_type = std::basic_string<CharT, Traits> |
| 字符串类型。 | |
| using | regex_type = std::basic_regex<CharT> |
| 正则表达式类型。 | |
| using | match_type = std::match_results<typename string_type::const_iterator> |
| 正则表达式的match_results类型。 | |
| using | flag_type = typename regex_type::flag_type |
| 标志类型。 | |
| using | iterator_type |
| 迭代器类型。 | |
| using | token_iterator |
| 词元类型。 | |
Public Member Functions | |
| BasicRegex (const string_type &pat, flag_type flags=regex_type::ECMAScript) | |
| 构造函数,初始化正则表达式模式。 | |
| Match | search (string_type text) const |
| 搜索第一个匹配。 | |
| Match | match (string_type text) const |
| 完全匹配整个文本。 | |
| Match | fullmatch (const string_type &text) const |
| 完全匹配整个文本。 | |
| std::vector< string_type > | findall (const string_type &text) const |
| 查找所有不重叠的匹配。 | |
| std::vector< string_type > | split (const string_type &text, int maxsplit=0) const |
| 使用正则表达式分割字符串。 | |
| string_type | sub (const string_type &repl, const string_type &text, int count=0) const |
| 替换匹配的子串。 | |
| std::pair< string_type, int > | subn (const string_type &repl, const string_type &text, int count=0) const |
| 替换匹配的子串并返回替换次数。 | |
Private Attributes | |
| regex_type | pattern |
| 正则表达式模式。 | |
正则表达式对象,封装编译后的模式,提供匹配、搜索、替换等功能。
| CharT | 字符类型(char 或 wchar_t)。 |
| Traits | 字符特征类型。 |
| using console::BasicRegex< CharT, Traits >::flag_type = typename regex_type::flag_type |
标志类型。
| using console::BasicRegex< CharT, Traits >::iterator_type |
迭代器类型。
| using console::BasicRegex< CharT, Traits >::match_type = std::match_results<typename string_type::const_iterator> |
正则表达式的match_results类型。
| using console::BasicRegex< CharT, Traits >::regex_type = std::basic_regex<CharT> |
正则表达式类型。
| using console::BasicRegex< CharT, Traits >::string_type = std::basic_string<CharT, Traits> |
字符串类型。
| using console::BasicRegex< CharT, Traits >::token_iterator |
词元类型。
|
inline |
构造函数,初始化正则表达式模式。
| pat | 正则表达式模式字符串。 |
| flags | 正则表达式标志,默认为ECMAScript。 |
|
inline |
查找所有不重叠的匹配。
| text | 要搜索的文本。 |
|
inline |
完全匹配整个文本。
| text | 要匹配的文本。 |
|
inline |
完全匹配整个文本。
| text | 要匹配的文本。 |
|
inline |
搜索第一个匹配。
| text | 要搜索的文本。 |
|
inline |
使用正则表达式分割字符串。
| text | 要分割的文本。 |
| maxsplit | 最大分割次数,默认为 0 表示不限制。 |
|
inline |
替换匹配的子串。
| repl | 替换字符串。 |
| text | 要替换的文本。 |
| count | 替换次数,默认为 0 表示替换所有匹配。 |
|
inline |
替换匹配的子串并返回替换次数。
| repl | 替换字符串。 |
| text | 要替换的文本。 |
| count | 替换次数,默认为 0 表示替换所有匹配。 |
|
private |
正则表达式模式。