KITFORMA · EDITORIAL ANSWER
Why does a literal dollar sign in Java regex replacement cause a group-reference error?
KitForma editorial guide. A replacement string has its own syntax; escaping the search pattern does not escape the replacement. Treat the two inputs independently.
Step-by-step answer
Matcher.quoteReplacement(replacement) to the matcher replacement operation. If both search and replacement are literal, consider String.replace instead of regex. Preserve regex group syntax only when your own replacement template deliberately uses it.
Verify a dollar sign, a backslash and text resembling a group reference. Check exact output rather than only the absence of exceptions. Quoting the replacement does not make an untrusted regular expression safe from expensive matching; bound input size and avoid accepting arbitrary regex where a literal search will do.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.