我有以下工作PHP代碼:php preg_match在C++中的等價物與Boost?
preg_match('/^(\d+):/', $string, $matches)
然而,當我嘗試做它在C++中使用Boost的正則表達式庫,它不工作。
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++,而不是C. – 2011-06-09 13:53:18
@develroot:「仍然不工作」沒有用。提供一個完整的,最小的測試用例來證明問題。我猜你的輸入字符串是不同的。用完整的代碼更新了 – 2011-06-09 13:54:14
。 – technology 2011-06-09 14:21:44