gpt4 book ai didi

javascript - 未捕获的语法错误 : Invalid regular expression in Chrome, FF 和 IE 正常

转载 作者:行者123 更新时间:2023-11-30 09:03:30 27 4
gpt4 key购买 nike

这行代码:

if ( new RegExp("\\b" + arrCategorySort[i]+ "\\b", "g").test(titleText) )
{
catFound = true;
}

在 Firefox (6.0) 和 IE (7.0) 中完美运行,但在 Chrome (13.0.782.112) 中运行不佳

你知道为什么吗?

最佳答案

在您的代码周围放置一个 try/catch 并显示导致异常的值:

try {
if ( new RegExp("\\b" + arrCategorySort[i]+ "\\b", "g").test(titleText) )
catFound = true;
}
catch (e) {
confirm (e + ' : at index ' + i + ', category is "' + arrCategorySort[i] + '"');
}

关于javascript - 未捕获的语法错误 : Invalid regular expression in Chrome, FF 和 IE 正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7146012/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com