{"record":{"id":"b1819d46e8d9a015","repo":"oxc-project/oxc","slug":"backreference-back-reference-will-be-ignored-b1819d","errorCode":null,"errorMessage":"Backreference '{back_reference}' will be ignored. It references group '{group}' which is in a negative lookaround.","messagePattern":"Backreference '(.+?)' will be ignored\\. It references group '(.+?)' which is in a negative lookaround\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs","lineNumber":32,"sourceCode":"    problem: &Problem,\n    back_reference: &str,\n    group: &str,\n) -> OxcDiagnostic {\n    let diagnostic = match problem {\n        Problem::Nested => OxcDiagnostic::warn(format!(\n            \"Backreference '{back_reference}' will be ignored. It references group '{group}' from within that group.\"\n        )),\n        Problem::Disjunctive => OxcDiagnostic::warn(format!(\n            \"Backreference '{back_reference}' will be ignored. It references group '{group}' which is in another alternative.\"\n        )),\n        Problem::Forward => OxcDiagnostic::warn(format!(\n            \"Backreference '{back_reference}' will be ignored. It references group '{group}' which appears later in the pattern.\"\n        )),\n        Problem::Backward => OxcDiagnostic::warn(format!(\n            \"Backreference '{back_reference}' will be ignored. It references group '{group}' which appears before in the same lookbehind.\"\n        )),\n        Problem::IntoNegativeLookaround => OxcDiagnostic::warn(format!(\n            \"Backreference '{back_reference}' will be ignored. It references group '{group}' which is in a negative lookaround.\"\n        )),\n    };\n    diagnostic\n        .with_help(\"Consider revising the pattern to remove or relocate the backreference so it points to a group that can be matched at the time of evaluation.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUselessBackreference;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows backreferences in regular expressions that will always be ignored\n    /// because the capture group they refer to has not matched and cannot match\n    /// at the time the backreference is evaluated.\n    ///\n    /// ### Why is this bad?","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs#L14-L50","documentation":"Diagnostic from `no-useless-backreference` (variant `IntoNegativeLookaround`). A backreference points at a capture group located inside a negative lookahead/lookbehind `(?!...)` / `(?<!...)`. A negative lookaround succeeds without matching, so its groups never retain a capture, and the backreference always matches the empty string. Oxc's analyzer detects the reference crossing into the negative lookaround and reports it.","triggerScenarios":"Patterns like `/(?!(a))\\1/` or `/(?<!(a))\\1/` where the referenced group is inside a negative lookaround and the backreference is used elsewhere in the pattern.","commonSituations":"Attempting to reuse text asserted-absent by a negative lookahead; refactoring a positive lookaround to negative while forgetting the backreference; machine-generated patterns combining assertions.","solutions":["Remove the backreference, since the negative-lookaround group is always empty at use time.","Move the capture group into the main pattern or a positive lookaround if you actually need its value: `/(a)(?!b)\\1/`-style restructuring.","Duplicate the subpattern instead of referencing the group inside the negative assertion.","Suppress with an inline oxlint disable comment only when targeting an engine with non-standard behavior."],"exampleFix":"// before\nconst re = /(?!(a))\\1x/;\n\n// after\nconst re = /(?!ax)x/; // assert absence without the dead reference","handlingStrategy":"validation","validationCode":"const refsGroupInNegativeLookaround = /\\(\\?![^)]*\\(([^)]*)\\)[\\s\\S]*\\\\1/.test(reSource);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never reference groups that live inside (?!...) or (?<!...) - they never capture.","Move needed captures into the main pattern or a positive lookaround.","Run oxlint on generated/merged regex constants to catch this automatically."],"tags":["lint","eslint","oxlint","regex","negative-lookahead"],"backgroundTag":"regex-backreference-negative-lookaround","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}