boost :: regex_search花费的时间太长 [英] boost::regex_search taking too long

查看:136
本文介绍了boost :: regex_search花费的时间太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一段代码将尝试从一段文本中提取URL(通过使用正则表达式).当文本很小时,我的代码可以正常工作,但是当文本很大时,boost::regex_search函数将花费近1分钟的时间来完成.

这是太多的执行时间,因为在其他文本上,boost::regex_search最多花费2毫秒,这是我的情况是可以接受的.但是,1分钟绝对太多了.

因此,我需要找到一种方法,在几毫秒后如何停止功能boost::regex_search.这有可能吗?还有其他解决方案吗?我不想更改正则表达式,因为它一直可以正确有效地工作.这个问题也是一个问题.

感谢您的宝贵时间,我们欢迎您提出任何建议.

Hi all,

I have a piece of code that will try to extract URLs (through the use of regexs) from a piece of text. My code works fine when the text is small, however, when having a very large text, the boost::regex_search function takes almost 1 minute to complete.

This is way too much executing time because on other texts, the boost::regex_search takes 2 milliseconds at most, which is my scenario is acceptable. However, 1 minute is definitely too much.

As such, I need to find a way how to stop the function boost::regex_search after a few milliseconds. Is this even possible? Are there other solutions to this? I don''t want to change the regex expression because it has always worked correctly and efficiently. Also this problem is a one off.

Thanks for your time and any suggestions are greatly welcome.

推荐答案

我认为阻止该功能不是一个选择(或者至少是一个不错的选择).您应该在表达式中发现缺陷(正则表达式确实存在陷阱,例如,参见失控正则表达式:灾难性的回溯" [ ^ ]).
I think blocking the function is not an option (or at least a good option). You should find the flaw in your expression (regular expressions do have pitfalls, see, for instance "Runaway Regular Expressions: Catastrophic Backtracking"[^]).


这篇关于boost :: regex_search花费的时间太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆