-1

I want to use javascript regexp to parse my bind9 zone file with comments, I tested it ok on https://regex101.com/r/qnoZbK/1, however I could not get group name in Chrome dev tools.

The test code is

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)
}

The following was the snapshot of my Chrome

enter image description here

Donghua Liu
  • 1,776
  • 2
  • 21
  • 30
  • 1
    Possible duplicate of [Named capturing groups in JavaScript regex?](https://stackoverflow.com/questions/5367369/named-capturing-groups-in-javascript-regex) – CinCout Sep 10 '19 at 03:06
  • @CinCout It was not the same issue with your provided link. The true problem was the new line character in the file. – Donghua Liu Sep 10 '19 at 08:41

2 Answers2

1

Finally, I figured out the issue, it was because I used babel in my project, the regexp in my project was wrapped via babel plugin (https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-named-capturing-groups-regex), and the version of it was old and may contain this kind of bug.

I could fix this problem with updating the dependences via yarn upgrade or ncu -u && yarn. Hope someone else who have the same issue could get help from this post.

Donghua Liu
  • 1,776
  • 2
  • 21
  • 30
0

I also find a problem, the same regexp may miss the group info sometimes.

The bad one.

enter image description here

The good one.

enter image description here

Donghua Liu
  • 1,776
  • 2
  • 21
  • 30