首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么不同的GCC 4.9.2安装会对这个正则表达式匹配产生不同的结果?

为什么不同的GCC 4.9.2安装会对这个正则表达式匹配产生不同的结果?
EN

Stack Overflow用户
提问于 2015-04-20 22:35:56
回答 1查看 1.1K关注 0票数 18

我在ideoneColiru上发布了以下代码

#include <iostream>
#include <regex>
#include <string>

int main() 
{
    std::string example{"   <match1>  <match2>    <match3>"};
    std::regex re{"<([^>]+)>"};
    std::regex_token_iterator<std::string::iterator> it{example.begin(), example.end(), re, 1};
    decltype(it) end{};
    while (it != end) std::cout << *it++ << std::endl;
    return 0;
}

两个站点都使用了GCC 4.9.2。我不知道ideone使用什么编译参数,但Coliru没有什么不寻常的。

Coliru没有给我match1结果:

Coliru

# g++ -v 2>&1 | grep version; \
# g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
gcc version 4.9.2 (GCC) 
match2
match3

ideone (顺便提一下,还有Coliru's clang 3.5.0 using libc++)

match1
match2
match3

我的代码是否有未定义的行为或什么?是什么导致了这种情况?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29750835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档