我正在玩Boost.Regex來解析字符和數字的字符串。這是我到目前爲止:你可以使用Boost.Regex來解析流嗎?
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/regex.hpp>
#include <boost/range.hpp>
using namespace std;
using namespace boost;
int main()
{
regex re
(
"("
"([a-z]+)|"
"(-?[0-9]+(\\.[0-9]+)?)"
")"
);
string s = "here is a\t list of Words. and some 1239.32 numbers to 3323 parse.";
sregex_iterator m1(s.begin(), s.end(), re), m2;
BOOST_FOREACH (const match_results<string::const_iterator>& what, make_iterator_range(m1, m2)) {
cout << ":" << what[1].str() << ":" << what.position(1) << ":" << what.length(1) << endl;
}
return 0;
}
有沒有辦法讓正則表達式從一個流而不是一個字符串解析?似乎應該可以使用任何迭代器。
你可以用``a「」b「`連接字符串而不用`+`嗎?哇,我從來沒有見過......那是標準嗎? – 2011-01-25 18:17:53