php preg_match 在 C++ 中与 Boost 的等价物?

标签 php c++ regex boost

我有以下有效的 php 代码:

preg_match('/^(\d+):/', $string, $matches)

但是,当我尝试使用 Boost 的正则表达式库在 C++ 中执行此操作时,它不起作用。

regex expression1("^(\\d+):"); 

std::string filename = "C:\\Users\\root\\Desktop\\something.bin";
std::ifstream ifs(filename.c_str(), std::ios::in | std::ios::binary);
std::string contents((std::istreambuf_iterator<char>(ifs)), 
std::istreambuf_iterator<char>());

cmatch what; 

if(regex_match(contents.c_str(), what, expression1))  
{ 
    cout<<"value is "<<what[1]<<endl;
} 

我不知道为什么。 regex_match 适用于其他模式,但不适用于这个 ^(\\d+):

最佳答案

\ 字符在 C 字符串中开始转义。试试 "^(\\d+):"

关于php preg_match 在 C++ 中与 Boost 的等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6293715/

相关文章:

c++ - 在链表末尾插入节点时出错

c++ - GCC 是否有编译器提示强制分支预测始终以某种方式进行?

javascript - 关于调整文本区域大小的指针

java - 空格分隔字符串java所需的正则表达式

javascript - Regex.compile 在 Ruby 中做什么?

php - 类的 Print_R 作为数组

php - MYSQL Select 基于 HTML 选择选项

php - Mysql监听事件

php数组导入mysql

c++ - 使用 CoDiPack 自动区分