Regex Replacement Literal Escape
Escape every dollar sign for literal ECMAScript string replacement; unlike regex pattern escaping this preserves replacement text semantics.
Description
Escape every dollar sign for literal ECMAScript string replacement; unlike regex pattern escaping this preserves replacement text semantics.
A literal replacement string needs dollar signs protected from substitution syntax. Pattern escaping is a different operation.1
When to use this tool
Escape every dollar sign for literal ECMAScript string replacement; unlike regex pattern escaping this preserves replacement text semantics.
- Prepare the supplied literal 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
- Enter literal. Use the exact text syntax, units and index conventions explained below.
- Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
- Read result.replacement. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.
Replace every dollar sign in literal by two dollar signs and return replacement.2
| Input field | Meaning and representation | Accepted input |
|---|---|---|
| literal | literal. | Text; at most 8,192 UTF-16 code units, subject to the grammar above |
| Output field | Interpretation |
|---|---|
| result | Object containing the named outputs below. |
| result.replacement | The replacement value under the stated formula or text convention. |
{
"input": {
"literal": "$1 $\u0026"
},
"output": {
"result": {
"replacement": "$$1 $$\u0026"
}
}
} Limitations and assumptions
- The result is intended for compatible JavaScript string-replacement semantics. It is not a regex pattern escape, HTML escape or callback 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
-
ECMAScript specification: GetSubstitution — Ecma International / TC39
-
Tool behavior and example: Regex Replacement Literal Escape — tool.io
Similar or alternative tools
- Literal Full Token Pattern Builder
Build a literal full-string ECMAScript pattern with a strict end assertion, avoiding dollar-anchor final-newline acceptance; assumes no multiline flag.
- 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.