{"record":{"id":"156bd643ea7dd591","repo":"oxc-project/oxc","slug":"backreference-back-reference-will-be-ignored-156bd6","errorCode":null,"errorMessage":"Backreference '{back_reference}' will be ignored. It references group '{group}' which appears before in the same lookbehind.","messagePattern":"Backreference '(.+?)' will be ignored\\. It references group '(.+?)' which appears before in the same lookbehind\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs","lineNumber":29,"sourceCode":"\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;\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","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs#L11-L47","documentation":"Diagnostic from `no-useless-backreference` (variant `Backward`). Inside a lookbehind, matching proceeds right-to-left, so a backreference that textually follows a group is evaluated before that group has captured; conversely a reference to a group that appears before it in the same lookbehind can never see a captured value in the way the author expects. Oxc flags the lookbehind-internal reference as always matching empty.","triggerScenarios":"A regex containing a lookbehind where a backreference and its group both live inside the same lookbehind, e.g. `/(?<=(a)\\1)/` or `/(?<=\\1(a))/`. The rule fires when the referenced group's span sits inside the same lookbehind as the backreference.","commonSituations":"Porting PCRE-style patterns that rely on right-to-left capture semantics; trying to assert repeated content immediately before a position using a backreference inside `(?<=...)`.","solutions":["Restructure the pattern so the capture happens outside the lookbehind and the reference sits in the forward direction, e.g. `/(?<=(a))\\1/`.","Repeat the subpattern literally inside the lookbehind instead of using a backreference.","Use a lookahead after the group: `/(a)(?<=\\1)/`-style ordering where the engine evaluates captures first.","Add an inline disable comment if you specifically target an engine with different lookbehind semantics."],"exampleFix":"// before\nconst re = /(?<=(a)\\1)x/;\n\n// after\nconst re = /(?<=(a))\\1x/;","handlingStrategy":"validation","validationCode":"// Avoid backreferences inside lookbehinds; assert with a quick sanity grep before commit\nconst usesBackrefInLookbehind = /\\(\\?<=.*(\\\\\\d+|\\\\k<[^>]+>).*\\)/.test(reSource);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Capture groups outside the lookbehind, reference them after it.","Remember lookbehind evaluates right-to-left; references to in-lookbehind groups are dead.","Test regexes against a runner (regex101 with the JS flavor) before committing."],"tags":["lint","eslint","oxlint","regex","lookbehind"],"backgroundTag":"regex-backreference-lookbehind","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"}