c++ - 使用 std::regex_match 匹配单个数字

标签 c++ regex

根据 this reference ,我应该能够将单个数字与

std::regex e1 ("\\d");  

但是,当我运行以下测试代码时,出现正则表达式异常。

#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 支持尚未准备就绪。请参阅:Is gcc 4.8 or earlier buggy about regular expressions?

关于c++ - 使用 std::regex_match 匹配单个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20525528/

相关文章:

python - 使用正则表达式抓取每次出现的内容

regex - 如何加入文件中的前n行

c++ - 运算符 [] 错误的矩阵类代理

c++ - 组件 X 的父类(super class)型未知,其某些属性未经过验证

c++ - 未定义的行为和顺序点

regex - 消除句点前的空格,除非后跟一个数字

c++ - regex_search 抛出 std::regex_error

c# - 使用正则表达式规范化电话号码

c++ - 文件描述符和套接字连接

c++ - 二进制永远不会构建