Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript regexp组信息有时可能会丢失_Javascript_Google Chrome_Debugging - Fatal编程技术网

Javascript regexp组信息有时可能会丢失

Javascript regexp组信息有时可能会丢失,javascript,google-chrome,debugging,Javascript,Google Chrome,Debugging,我编写了一个带有命名组的正则表达式,ant在Chrome开发工具的控制台上测试了它,但当我将它添加到脚本并运行时,组信息丢失了 测试代码是这样工作的 const contents = `; the is some comment name1 IN CNAME value1 name2 IN A value2 ;name3 IN A value3 ; the is another comment name4

我编写了一个带有命名组的正则表达式,ant在Chrome开发工具的控制台上测试了它,但当我将它添加到脚本并运行时,组信息丢失了

测试代码是这样工作的

const contents = `; the is some comment
name1           IN  CNAME   value1
name2           IN  A   value2
;name3          IN  A   value3
; the is another comment
name4           IN  A   value4`

const regexp = /(?:^;\s*(?<comment>.+?)\s*$\n)?^\s*(?!;)(?<name>.*?)\s+(?<className>.*?)\s+(?<type>.*?)\s+(?<value>.*?)$/gm

const matches = contents.matchAll(regexp)
for (const match of matches) {
  console.info(match)
}
const contents=`;这是一些评论
CNAME value1中的名称1
在value2中命名2
;在值3中命名3
; 这是另一个评论
在value4中命名4`
常量regexp=/(?:^;\s*(?。+?)\s*$\n)?^\s*(?!;)(?*?)\s+(?*?)\s+(?*?)\s+(?*?)\s+(?*?)$/gm
常量匹配=contents.matchAll(regexp)
for(连续匹配){
控制台信息(匹配)
}
下面是Chrome开发者的快照


这真的很奇怪,当我调试它时,它总是有组名信息,但在脚本中运行时却没有。最后,我发现了这个问题,因为我在我的项目中使用了babel,我的项目中的regexp是通过babel插件()包装的,它的版本很旧,可能包含这种错误


我可以通过
纱线升级
ncu-u&&warn
更新依赖项来解决此问题。希望其他有同样问题的人能从这篇文章中得到帮助。

我不完全确定你在问什么。当我运行您的脚本并调试它时,
regexp
似乎包含所有组(在Chrome 76上),它的定义没有改变。或者您是否希望
console.info
产生其他结果?@CertainPerformance,您好,我的问题是,如果我在脚本中运行相同的代码,那么
console.info(`regexp`,regexp)
将不显示组信息。