问题描述
我的内容带有<del></del>
和<ins></ins>
标记.我有一个正则表达式,可以满足图片中清楚说明的条件
I have a content with <del></del>
and <ins></ins>
tags. I have a regex which satisfies the conditions which are clearly explained in the image
http://i.stack.imgur.com/8iNWl.png
满足条件的正则表达式是
The regex which satisfies the conditions is
https://regex101.com/r/cE4mE3/19
此正则表达式运行正常.但是,当内容更多或匹配内容很长时,执行时间会增加,从而引发超时错误,该错误可在regex101.com/r/cE4mE3/20
This regex is working perfectly fine. But, when the content is more or When the matching content is long the execution time is increasing and hence throwing a timeout error which can be seen in regex101.com/r/cE4mE3/20
如何简化正则表达式(\w*(?:(?:(?:<del\b[^>]*>(?:(?!<\/del>).)*<\/del>)|(?:<ins\b[^>]*>\w+<\/ins>)|(?:\w+<\/ins>)|(?:<ins\b[^>]*>\w+))(?:\w+|))+)
以避免引发超时错误
How to simplify the regex (\w*(?:(?:(?:<del\b[^>]*>(?:(?!<\/del>).)*<\/del>)|(?:<ins\b[^>]*>\w+<\/ins>)|(?:\w+<\/ins>)|(?:<ins\b[^>]*>\w+))(?:\w+|))+)
to avoid it from throwing timeout error
推荐答案
正则表达式不是正确的方法.您自己发现了一个陷阱.还有更多.因此请切换到DOM分析器.要消除超时问题,您可以尝试
Regex is not correct way to do this.You yourself have discovered a pitfall.There will be more.So switch to DOM parser .As for removing the timeout issue , you can try
((?=(\w*))\2(?:(?:(?:<del\b[^>]*>(?:(?!<\/del>).)*<\/del>)|(?:<ins\b[^>]*>\w+<\/ins>)|(?:\w+<\/ins>)|(?:<ins\b[^>]*>\w+))(?:\w+|))+)
请参阅演示.
https://regex101.com/r/cE4mE3/24
这篇关于正则表达式超时错误jQuery/JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!