Regex Replacement Reference Audit

Audit replacement references against an explicit capture count/name bank, accounting for two-digit-to-one-digit fallback; unresolved references remain literal in ECMAScript, not execution errors.

Description

Audit replacement references against an explicit capture count/name bank, accounting for two-digit-to-one-digit fallback; unresolved references remain literal in ECMAScript, not execution errors.

A replacement reference may name a capture that does not exist. Numbered references can also use a one-digit fallback.1

When to use this tool

Audit replacement references against an explicit capture count/name bank, accounting for two-digit-to-one-digit fallback; unresolved references remain literal in ECMAScript, not execution errors.

  • Prepare the supplied replacement, captureCount, names fields for this operation.
  • Compare the complete example with the representation used by your own input before carrying the result into another step.

How to use the tool and how it works

  1. Enter replacement, captureCount, names. Use the exact text syntax, units and index conventions explained below.
  2. Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
  3. Read result.issues. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.

Tokenize replacement, require captureCount from 0 to 99 and use names as the declared named captures. Report unknown names and numbered references that have neither an existing full number nor a valid positive first-digit fallback.2

Input fieldMeaning and representationAccepted input
replacementreplacement.Text; at most 8,192 UTF-16 code units, subject to the grammar above
captureCountcapture count.Integer from 0 to 99 inclusive
namesnames.List of strings; at most 128 entries
Output fieldInterpretation
resultObject containing the named outputs below.
result.issuesThe issues list in the ordering and representation described above.
json
{
  "input": {
    "replacement": "$1 $2 $\u003cx\u003e",
    "captureCount": 1,
    "names": []
  },
  "output": {
    "result": {
      "issues": [
        {
          "type": "numbered",
          "text": "$2",
          "position": 3
        },
        {
          "type": "named",
          "text": "$\u003cx\u003e",
          "position": 6
        }
      ]
    }
  }
}

Limitations and assumptions

  • The pattern and match are not inspected. Issues flag unresolved references under this declared schema; they do not mean JavaScript necessarily throws on replacement.
  • All declared input fields are required and unexpected top-level fields are rejected. Numbers must be finite; lists are limited to 128 entries and ordinary text fields to 8,192 UTF-16 code units, with tighter limits where stated.
  • JSON text inputs must parse within bounded nesting and size limits. Numeric outputs outside the safe finite range are rejected; large exact integer results use decimal strings. Indexes and half-open spans are zero-based unless a rank is explicitly described as one-based.

Alternative or Complementary methods

Compile generated pattern sources with explicitly chosen flags and test them on bounded representative text. Pattern sources, replacement strings and JSON string spellings require different escaping conventions.

References

  1. ECMAScript specification: GetSubstitution — Ecma International / TC39

  2. Tool behavior and example: Regex Replacement Reference Audit — tool.io

Similar or alternative tools

  • Regex Replacement Literal Escape

    Escape every dollar sign for literal ECMAScript string replacement; unlike regex pattern escaping this preserves replacement text semantics.

  • Regex Replacement Tokenizer

    Tokenize ECMAScript replacement-dollar syntax without applying matches; numeric reference resolution depends on separately supplied capture evidence.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies