{"record":{"id":"813e82a5278a852c","repo":"oxc-project/oxc","slug":"backreference-back-reference-will-be-ignored-813e82","errorCode":null,"errorMessage":"Backreference '{back_reference}' will be ignored. It references group '{group}' which is in another alternative.","messagePattern":"Backreference '(.+?)' will be ignored\\. It references group '(.+?)' which is in another alternative\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs","lineNumber":23,"sourceCode":"    ast::LookAroundAssertionKind,\n    visit::{RegExpAstKind, Visit},\n};\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::run_on_regex_node};\n\nfn no_useless_backreference_diagnostic(\n    span: Span,\n    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;","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs#L5-L41","documentation":"no-useless-backreference, Disjunctive case: the backreference sits in one alternative of an alternation while its target group only participates in a different alternative. On this path the group never captured anything, so the backreference can never match non-empty text and is dead weight in the pattern.","triggerScenarios":"Regex literals like /(a)|(\\1)/ or /(?:x(y))|(?:\\1z)/ where the referenced group lives in the other branch of the alternation.","commonSituations":"Combining two regexes with | after refactoring; alternations where each branch was meant to share a common token; hand-grown URL/date matchers.","solutions":["Duplicate the subpattern explicitly in each alternative instead of backreferencing across branches: /^(a)|(a)$/.","Restructure so the referenced group encloses the whole alternation that uses it.","Remove the dead backreference if the shared-token intent was wrong."],"exampleFix":"// before\nconst re = /^(a)|(\\1)$/;\n// after\nconst re = /^(a)|(a)$/;","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never backreference across alternation branches; duplicate the subpattern in each branch instead.","After merging regexes with |, re-check that every backreference's group encloses its position.","Cover regex changes with unit tests so alternation regressions surface before lint does."],"tags":["eslint","oxlint","regex","backreference","alternation"],"backgroundTag":"useless-regex-backreference","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"}