¿
¿ÖÐ
#include <iostream>
#include <string>
#include <boost/regex.hpp>
using namespace std;
int main(int argc, char* argv[])
{
string inStr =
"123456"
"abcde"
"1-2";
std::string regstr =
"(\\d+)|"
"(a-z)";
boost::regex _reg(regstr);
boost::smatch what;
std::string::const_iterator _start = inStr.begin();
std::string::const_iterator _end = inStr.end();
while (boost::regex_search(_start, _end, what, _reg))
{
std::string msg1(what[1].first, what[1].second);
cout << msg1.c_str() << endl;
_start = what[1].second;
}
return 0;
}
run result:
123456
1
2
why can't find "abcde"?
#include <string>
#include <boost/regex.hpp>
using namespace std;
int main(int argc, char* argv[])
{
string inStr =
"123456"
"abcde"
"1-2";
std::string regstr =
"(\\d+)|"
"(a-z)";
boost::regex _reg(regstr);
boost::smatch what;
std::string::const_iterator _start = inStr.begin();
std::string::const_iterator _end = inStr.end();
while (boost::regex_search(_start, _end, what, _reg))
{
std::string msg1(what[1].first, what[1].second);
cout << msg1.c_str() << endl;
_start = what[1].second;
}
return 0;
}
run result:
123456
1
2
why can't find "abcde"?