Console Library 4.7.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
re.h File Reference

提供正则表达式匹配、搜索、替换、分割等操作,接口类似 Python 的 re 模块。 More...

#include <regex>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

class  console::Regex
 正则表达式对象,封装编译后的模式,提供匹配、搜索、替换等功能。 More...
class  console::Regex::Match
 匹配结果对象,包含匹配信息。 More...
class  console::Regex::Iterator
 迭代器,用于遍历所有匹配。 More...
class  console::Regex::IteratorPair
 包装起始和结束迭代器,支持范围 for 循环。 More...

Namespaces

namespace  console
 本库所有组件所在的顶层命名空间。
namespace  re
 函数式正则表达式接口,模仿 Python 的 re 模块。
namespace  console::re

Functions

Regex console::re::compile (const std::string &pattern, std::regex::flag_type flags=std::regex::ECMAScript)
 编译正则表达式并返回 Regex 对象。
Regex::Match console::re::search (const std::string &pattern, const std::string &text)
 搜索第一个匹配(函数式接口)。
Regex::Match console::re::match (const std::string &pattern, const std::string &text)
 从开头匹配(函数式接口)。
std::vector< std::string > console::re::findall (const std::string &pattern, const std::string &text)
 查找所有匹配的字符串(函数式接口)。
std::vector< std::string > console::re::split (const std::string &pattern, const std::string &text, int maxsplit=0)
 分割字符串(函数式接口)。
std::string console::re::sub (const std::string &pattern, const std::string &repl, const std::string &text, int count=0)
 替换匹配的子串(函数式接口)。
std::string console::re::escape (const std::string &s)
 转义正则表达式中的特殊字符。

Detailed Description

提供正则表达式匹配、搜索、替换、分割等操作,接口类似 Python 的 re 模块。

封装了 C++ 标准库的 std::regex,提供更便捷的面向对象和函数式接口。

Author
MrXie1109
Date
2026