求一个有关捕获组的正则表达式

blldw blldw 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

std::string str = "port 1-100, 2-200, 5-500";
std::regex reg("port\\s?((\\d+\\s*-\\s*\\d+)[,|\\s]*)+");
std::smatch match_result;
bool matched = std::regex_match(str, match_result, reg);
for (int i = 0; i < match_result.size(); ++i) {
std::cout << match_result[i] << std::endl;
}


为什么match_result的结果只能够把5-500捕获到,而1-100和2-200都捕获不到呢?求原因和解决方法。
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
blldw
C++ 语言 65,212 成员 250,513 内容