Hello,
I'm trying to port my old regex code from pcre to boost.regex. There is a sample:
void print_captures(const std::string& regx, const std::string& text)
{
boost::regex e(regx, boost::regex::perl);
boost::smatch what;
std::cout << "Expression: \"" << regx << "\"\n";
std::cout << "Text: \"" << text << "\"\n";
if(boost::regex_search(text, what, e, boost::match_extra))
{
unsigned i, j;
for(i = 0; i < what.size(); ++i)
std::cout << " $" << i << " = \"" << what[i] << "\"\n";
}
else
{
std::cout << "** No Match found **\n";
}
}
int main(int , char* [])
{
print_captures("http:\\/\\/.*\\.(.*\\.cn)", "\n\nhttp://www.sc500.cn/hi/mom! \
\n test http:// rdfhr.zeyulariy.cn \
\n test http:// adtgr.zeytlariy.cn \n \
http://super.test.com");
return 0;
}
boost::regex output is:
$0 = "http://www.sc500.cn/hi/mom!
test http:// rdfhr.zeyulariy.cn
test http:// adtgr.zeytlariy.cn"
$1 = "zeytlariy.cn"
Whereas where I'm using pcre I got following substrings (except full match):
sc500.cn
zeytlariy.cn
zeyulariy.cn
which is expected. So I'm confused about how perl expressions are worked. How can I get the same results using boost instead of pcre?
Thank you.