Names of regular expressions named groups should be used for self reference

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for?

JavaScript

  • Which rule?

unused-named-groups

  • Why do you believe it’s a false-positive/false-negative?

The \1 can not use group name quote, and <quote> is for meaningful group

  • Are you using

SonarQube Cloud?

  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
const codeBlockFileNameRegex = /filename=(?<quote>["'])(?<filename>.*?)\1/u

Just learn that we can use \k<quote> instead of \1:

const codeBlockFileNameRegex = /filename=(?<quote>["'])(?<filename>.*?)\k<quote>/u

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.