GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.runoob.com — C++ 标准库 <regex> | 菜鸟教程
C++ 教程
C++ 教程
C++ 简介
C++ 环境设置
C++ 基本语法
C++ 注释
C++ 数据类型
C++ 变量类型
C++ 变量作用域
C++ 常量
C++ 修饰符类型
C++ 存储类
C++ 运算符
C++ 循环
C++ 判断
C++ 函数
C++ 数字
C++ 数组
C++ 字符串
C++ 指针
C++ 引用
C++ 日期 & 时间
C++ 基本的输入输出
C++ 结构体(struct)
C++ vector 容器
C++ 数据结构
C++ 面向对象C++ 类 & 对象 C++ 继承 C++ 重载运算符和重载函数 C++ 多态 C++ 数据抽象 C++ 数据封装 C++ 接口(抽象类)C++ 高级教程C++ 文件和流 C++ 异常处理 C++ 动态内存 C++ 命名空间 C++ 模板 C++ 预处理器 C++ 信号处理 C++ 多线程 C++ Web 编程C++ 资源库C++ STL 教程 C++ 导入标准库 C++ 标准库 C++ 有用的资源 C++ 实例 C++ 测验 C++ <iostream> C++ <fstream> C++ <sstream> C++ <iomanip> C++<array>
C++ <vector>
C++ <list>
C++ <forward_list>
C++ <deque>
C++ <stack>
C++ <queue>
C++ <priority_queue>
C++ <set>
C++ <unordered_set>
C++ <map>
C++ <unordered_map>
C++ <bitset>
C++ <algorithm>
C++ <iterator>
C++ <functional>
C++ <numeric>
C++ <complex>
C++ <valarray>
C++ <cmath>
C++ <string>
C++ <regex>
C++ <ctime>
C++ <chrono>
C++ <thread>
C++ <mutex>
C++ <condition_variable>
C++ <future>
C++ <atomic>
C++ <type_traits>
C++ <typeinfo>
C++ <exception>
C++ <stdexcept>
C++ <cstdio>
C++ <cstdint>
C++ <memory>
C++ <new>
C++ <utility>
C++ <random>
C++ <locale>
C++ <codecvt>
C++ <cassert>
C++ <cwchar>
C++ <climits>
C++ <cfloat>
C++ <cstdlib>
C++ <numbers>
C++ OpenCV
C++ 标准库
|
| 名称 | 说明 |
|---|---|
std::regex |
编译正则表达式对象 |
std::smatch |
std::string 匹配结果 |
std::cmatch |
C 字符串匹配结果 (const char*) |
std::sregex_iterator |
用于 std::string 的匹配迭代器 |
std::cregex_iterator |
用于 C 字符串的匹配迭代器 |
std::syntax_option_type |
正则语法选项 |
std::match_flag_type |
匹配控制标志 |
| 函数名 | 用途 | 返回值 | 示例 |
|---|---|---|---|
regex_match(s, re) |
检查整串是否匹配 | bool |
regex_match("123", re) |
regex_search(s, m, re) |
查找第一个匹配 | bool |
regex_search(s, m, re) |
regex_replace(s, re, fmt) |
替换匹配项 | string |
regex_replace(s, re, "#") |
smatch 匹配结果对象| 成员 | 说明 | 示例 |
|---|---|---|
m.str() |
返回整个匹配到的内容 | cout << m.str() |
m[i] |
返回第 i 个捕获组 | m[1].str() |
m.position() |
匹配起始位置 | m.position(0) |
m.size() |
捕获组数量 | m.size() |
m.empty() |
是否匹配为空 | m.empty() |
| 符号 | 含义 | 示例 | ||
|---|---|---|---|---|
. |
任意字符 | a.c 匹配 abc |
||
\d |
数字 | \d+ |
||
\w |
字母数字下划线 | \w+ |
||
\s |
空白字符 | \s+ |
||
^ |
开头 | ^abc |
||
$ |
结尾 | xyz$ |
||
+ |
1 次或多次 | a+ |
||
* |
0 次或多次 | a* |
||
? |
0 次或 1 次 | a? |
||
{n,m} |
n~m 次 | \d{2,4} |
||
() |
捕获分组 | (ab)+ |
||
[] |
字符集 | [A-Z] |
||
| ` | ` | 或 | `cat | dog` |
在 C++ 源码字符串中要写 \\d 而不是 \d,因为 \ 需要转义。
取消