// Note that this is not wrapped in parentheses,
// since it is two separate sets of nested parentheses
var test = "(the OR (and) OR (and) OR (and)) AND ((to) OR (to) OR (to))";
isWrappedInParens = function(str){
if(_.isNull(str)) {
return false;
}
str = str.trim();
var pattern = /^[(](([(][^()]+[)]|[^()]+)|[(]([(][^()]+[)]|[^()]+)+[)])+[)]$/;
var matchesPattern;
try{
matchesPattern = str.match(pattern) || null; //CRASH POINT!!!!!!!!!!!
}catch(err){
return false; //Note that no error is ever caught from freezing
}
var isWrapped = !_.isUndefined(matchesPattern) && !_.isNull(matchesPattern);
return isWrapped;
}
// Atoms, building blocks for the expressions
var parenAtom = "[(][^()]+[)]";
var nonParenAtom = "[^()]+";
// Expressions, building blocks for the final regular expression
var baseCase = "(" + parenAtom + "|" + nonParenAtom + ")";
var nestedCase = "[(]_base_[)]"
.replace("_base_", baseCase);
// Regular Expression
var wholeCase = "^[(](_base_|_nested_)+[)]$"
.replace("_base_", baseCase)
.replace("_nested_", nestedCase);
var pattern = new RegExp(wholeCase, "");
答案 0 :(得分:1)
来自我的评论:
查看Firefox错误数据库,发现了许多正则表达式错误,并将其松散地归类为“指数行为”错误。其中大多数已在较新版本的浏览器中修复。
In this bug Brendan Eich有一些关于这个问题的评论,他列出了其他几个错误(有些很老)。另一个评论暗示Firefox 4中的“正则表达式大修”,表明很多变化都发生在那时。