Android - Matcher.find() infinite

北城余情 提交于 2019-12-02 21:36:56

问题


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.

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/17674839/android-matcher-find-infinite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!