oxc-project/oxc · warning · OxcDiagnostic

Backreference '{back_reference}' will be ignored. It referen

Error message

Backreference '{back_reference}' will be ignored. It references group '{group}' from within that group.

What it means

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).

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_useless_backreference.rs:20

use oxc_index::{IndexVec, define_nonmax_u32_index_type};
use oxc_macros::declare_oxc_lint;
use oxc_regular_expression::{
    ast::LookAroundAssertionKind,
    visit::{RegExpAstKind, Visit},
};
use oxc_span::Span;

use crate::{AstNode, context::LintContext, rule::Rule, utils::run_on_regex_node};

fn no_useless_backreference_diagnostic(
    span: Span,
    problem: &Problem,
    back_reference: &str,
    group: &str,
) -> OxcDiagnostic {
    let diagnostic = match problem {
        Problem::Nested => OxcDiagnostic::warn(format!(
            "Backreference '{back_reference}' will be ignored. It references group '{group}' from within that group."
        )),
        Problem::Disjunctive => OxcDiagnostic::warn(format!(
            "Backreference '{back_reference}' will be ignored. It references group '{group}' which is in another alternative."
        )),
        Problem::Forward => OxcDiagnostic::warn(format!(
            "Backreference '{back_reference}' will be ignored. It references group '{group}' which appears later in the pattern."
        )),
        Problem::Backward => OxcDiagnostic::warn(format!(
            "Backreference '{back_reference}' will be ignored. It references group '{group}' which appears before in the same lookbehind."
        )),
        Problem::IntoNegativeLookaround => OxcDiagnostic::warn(format!(
            "Backreference '{back_reference}' will be ignored. It references group '{group}' which is in a negative lookaround."
        )),
    };
    diagnostic
        .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.")
        .with_label(span)
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the self-referencing backreference and use an explicit repetition: /(abc)+/.
  2. If you need to match the same text twice, capture once and reference the group from outside it.
  3. Validate the pattern in a regex tester that flags backreference scope issues before committing.

Example fix

// before
const re = /(abc\1)+/;
// after
const re = /(abc)+/;
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: 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.

Common situations: Hand-written 'repeat the same text' attempts such as /(abc\1)+/; porting PCRE habits; generated or AI-produced regexes nobody executed.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/ee009b3b2adfb4ab. Report an issue: GitHub.