{"record":{"id":"ee009b3b2adfb4ab","repo":"oxc-project/oxc","slug":"backreference-back-reference-will-be-ignored","errorCode":null,"errorMessage":"Backreference '{back_reference}' will be ignored. It references group '{group}' from within that group.","messagePattern":"Backreference '(.+?)' will be ignored\\. It references group '(.+?)' from within that group\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs","lineNumber":20,"sourceCode":"use oxc_index::{IndexVec, define_nonmax_u32_index_type};\nuse oxc_macros::declare_oxc_lint;\nuse oxc_regular_expression::{\n    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}","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs#L2-L38","documentation":"Diagnostic from oxlint's no-useless-backreference rule, Nested case. A regex backreference placed inside the very group it references can never see captured text because that group is still open, so the backreference can only match empty and the pattern never behaves as intended. oxc parses the literal (run_on_regex_node) and classifies the defect (Nested/Disjunctive/Forward/Backward/IntoNegativeLookaround).","triggerScenarios":"Regex literals like /(a\\1)/ or /((a\\2)b)/ where the backreference sits inside its own target group, often written while attempting to repeat a subpattern.","commonSituations":"Hand-written 'repeat the same text' attempts such as /(abc\\1)+/; porting PCRE habits; generated or AI-produced regexes nobody executed.","solutions":["Remove the self-referencing backreference and use an explicit repetition: /(abc)+/.","If you need to match the same text twice, capture once and reference the group from outside it.","Validate the pattern in a regex tester that flags backreference scope issues before committing."],"exampleFix":"// before\nconst re = /(abc\\1)+/;\n// after\nconst re = /(abc)+/;","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use explicit repetition ((abc)+) instead of backreferences when repeating literal text.","Test regex literals in a checker that reports backreference scope (regex101 shows 'group has not been captured' warnings).","Keep regexes small; a backreference inside its own group is usually a symptom of an oversized pattern."],"tags":["eslint","oxlint","regex","backreference"],"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-14T00:17:10.932Z"}