繁体   English   中英

使用std :: regex_match匹配单个数字

[英]Matching single digit with std::regex_match

根据这个参考 ,我应该能够匹配一个数字

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支持尚未准备好迎接黄金时段。 请参阅: gcc 4.8或更早版本关于正则表达式的错误吗?

如果std :: regex支持仍然是错误的,因为@qwrrty建议,字符类'[0-9]'代替'\\d'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM