首页 > 解决方案 > 积极的前瞻在浏览器的控制台中不起作用,但在 regxr.com 中起作用

问题描述

以下 2 个正则表达式按我的预期工作,在 www.regxr.com 如果我在浏览器的控制台中运行示例,则匹配似乎忽略了积极的前瞻。这是否意味着浏览器(chrome)不支持它?

let regex1 = new RegExp(/(?<=uploaded\s+).*(?=\s+new file)/gi);
let regex2 = new RegExp(/(?<!-)\d+(?=\s+-)/gi);

let input = 'Hi UPR, ' + 
'Ryan Anderson uploaded one new file to your request for Fname Lname - 743245 - CS4:' +
'Ryan Anderson - Screen Shot 2020-06-08 at 1.10.39 pm.png ' + 
'See new files'

let matches = [];
while ((matches = regex1.exec(input)) !== null) {
  console.log(`Found [${matches[0]}]. Next starts at ${regex1.lastIndex}.`);
}

标签: javascriptregex

解决方案


推荐阅读