请教个正则表达式的问题

jieao111 2016-07-09 10:55:57
std::string getregex(std::string tmptxt)
{
boost::smatch mat;
const char* pattern ="《(.*?)》";
boost::regex ip_regex(pattern);
boost::regex_search(tmptxt, mat, ip_regex);
cout<<mat.size();
for (size_t i = 0; i < mat.size(); ++i)
{
std::cout << "dd"<<mat[i] << std::endl;
}
//cout<<r;
boost::sregex_iterator it(tmptxt.begin(), tmptxt.end(), ip_regex);
boost::sregex_iterator end;
for (; it != end; ++it) {
std::cout << it->str() << "\n";
}
return "";
}
int main()
{
std::string ti="《欢乐颂》里的每个姑娘其实都是你 关雎尔好人难做不《欢乐颂》完结 扒一扒22楼女>神们的手机-科技频道-.九个《欢乐颂》经典语录,女孩子们最好看看!-搜狐";
std::string desc="和其他都市女性剧不同,《欢乐颂》中五个女性形象完全打破了欢乐颂剧照";
getregex(ti);
return 0;
}


很奇怪,这两个输出不一样regex_search和sregex_iterator,,为什么regex_search会少一个结果。。。还有一个问题,我想提取出不包含《》的结果,该怎么写
...全文
132 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ID870177103 2016-07-10
  • 打赏
  • 举报
回复
(?<=《)\w+(?=》)

64,266

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧