Android的 - Matcher.find()无限 [英] Android - Matcher.find() infinite

查看:223
本文介绍了Android的 - Matcher.find()无限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现的AsyncTask,其中由用户提供的常规前pression被用于匹配巨大HTML- code数据。但是,由于一些正规的前pressions含有大量的量词/回溯,Matcher.find()变为无限。

I have implemented AsyncTask where the regular expression provided by the user is being used for matching huge html-code data. However, because some of the regular expressions contain a lot of quantifiers/backtracking, Matcher.find() goes infinite.

我曾尝试使用 InterruptibleCharSequence 这里提供:<一href=\"http://stackoverflow.com/questions/7125732/how-to-terminate-matcher-find-when-its-running-too-long\">How终止Matcher.find(),当其运行时间太长?,但似乎的的charAt 的是永远不会被调用,所以从未中断。最后,我的猜测是刚刚创建一个新的进程来运行这个规律的匹配过程,然后杀了它在搜索时会被取消。不过,后来我有一个问题,共享服务和活动的对象,因为不同的流程。

I have tried to use InterruptibleCharSequence provided here: How to terminate Matcher.find(), when its running too long?, but it seems that charAt is never get called, so never interrupted. My last guess is to create a new process just to run this regular matching procedure and then kill it when searching is cancelled. However, then I have a problem with sharing objects between Service and Activity, because of different processes.

推荐答案

使用RegEx解析HTML是一个坏主意,请参见:的解析HTML邪神之路

Parsing HTML using RegEx is a bad idea, see: Parsing Html The Cthulhu Way

有关解析DOM,而不是么?我试着 jsoup 前一段时间,发现它pretty整齐的工作。

What about parsing the DOM instead? I tried jsoup a while ago and found it pretty neat to work with.

这篇关于Android的 - Matcher.find()无限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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