jjzjj

catastrophic

全部标签

javascript - 如何使正则表达式不导致 “catastrophic backtracking” ?

当我尝试在javascript中运行以下代码时,浏览器由于灾难性的回溯而挂起,回溯无限循环可能是因为设计不当的正则表达式。我需要一个替代表达式或一种方法来防止这个问题:stringtemp="Testingrobustness{parent-area-identifierSometextinbetweenthetokens{parent-area-label}";varstrRegExp=newRegExp(/[{](?:[^{}]+|[{][^{}]*[}])*[}]/g);vararrMatch=temp.match(strRegExp); 最佳答案

javascript - 我怎样才能使这个正则表达式不导致 "catastrophic backtracking"?

我正在尝试使用从http://daringfireball.net/2010/07/improved_regex_for_matching_urls获得的URL匹配正则表达式(?xi)\b(#Capture1:entirematchedURL(?:https?://#httporhttpsprotocol|#orwww\d{0,3}[.]#"www.","www1.","www2."…"www999."|#or[a-z0-9.\-]+[.][a-z]{2,4}/#lookslikedomainnamefollowedbyaslash)(?:#Oneormore:[^\s()]+#Run