奇怪的bug

编程入门 行业动态 更新时间:2024-10-24 10:24:00
本文介绍了奇怪的bug - std :: regex只匹配前两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

今天我在我的应用程序中遇到了奇怪的错误。我测试了2个小时,没有找到解决方案。也许你可以帮助我解决这个问题。所以这里是:

Today I encountered strange bug in my application. I've tested it for like 2 hours and didn't find a solution. Maybe you can help me solving this problem. So here it is:

#include <iostream> #include <regex> #include <vector> int main() { std::regex reg("rmvb|avi|rm|mp4|256"); std::vector<std::string> ext{"rmvb", "avi", "rm", "mp4", "256", "null"}; for (int i = 0; i < 6; i++) { std::cout << ext[i] << "\t" << std::boolalpha << std::regex_match(ext[i], reg) << std::endl; } return 0; }

输出:

rmvb true avi true rm false mp4 false 256 false null false

似乎模式被丢弃后的第二个元素 - 无论我选择什么顺序(我试图交换他们,可以导致这个bug - 但他们不是)。现在我不知道发生了什么。

It seems that pattern is discarded after the second element - no matter what order I choose (I tried to swap them, because I thought that digits can cause this bug - but they aren't). Now I have no idea what's going on.

我使用gcc 4.6.3版本(Debian 4.6.3-1)。

I'm using gcc version 4.6.3 (Debian 4.6.3-1).

推荐答案

regex库大多数还没有在libstc ++中实现(cf. 状态页)。这可能是一个错误或只是其未实现的结果。建议您使用 Boost.Regex 作为替代品。

The regex library is mostly not yet implemented in libstc++ (cf. status page). This may be a bug or just the result of it not being implemented. I'd suggest using Boost.Regex as a replacement.

更多推荐

奇怪的bug

本文发布于:2023-11-10 21:55:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:奇怪   bug

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!