用std::regex_match匹配个位数
Matching single digit with std::regex_match
根据这个参考,我应该能够将一个数字与匹配
std::regex e1 ("\d");
然而,当我运行以下测试代码时,我会得到一个regex异常。
#include <iostream>
#include <string>
#include <regex>
int main()
{
std::regex r("\d");
std::string s("9");
if (std::regex_match(s, r)) { std::cout << "matched!" << std::endl; }
}
GCC的std::regex
支持还没有准备好进入黄金时段。请参阅:gcc 4.8或更早版本对正则表达式有缺陷吗?
如果std::regex支持仍然像@qwrrty所建议的那样有缺陷,那么字符类'[0-9]'
就是'd'
的替代品。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::原子加载和存储都需要吗
- 如何修复以下错误"no match for call to '(std::tr1::shared_ptr<_iobuf*>) (FILE*&)'"
- 引入 std::enable_if 后出现"No match"错误
- 如何修复" no match for 'operator<<' in 'std::cout"错误?
- 使用 std::string 时"error: no match for ‘operator<<"
- 初始化标准::auto_ptr:"error: no match for call to ‘(std::auto_ptr<int>) (int*)’"
- 在 -std=c++11 上编译时C++ "no match for operator >>"
- 'No Match' 使用 std::tr1::函数的成员回调函数出错