replaceAll treats input as regex
String.replaceAll interprets its first argument as a regular expression and replacement metacharacters specially. Use replace for literal text or quote patterns and replacements when needed.
Matcher.quoteReplacementescapes a replacement string, andPattern.quoteescapes the search pattern. If you have hit a variant of this, share it below.replaceAll compiles its first argument as a regex and treats dollar signs and backslashes in the replacement as special. For a plain literal substring, replace avoids both interpretations.
Specific and to the point: "replaceAll treats input as regex". Worth a look if you touch java / regex.
Clear note on java / regex. "replaceAll treats input as regex" is the kind of detail that is easy to overlook.
Because replaceAll is regex-based, a literal string containing metacharacters can match unexpectedly or fail. Literal substitution is clearer with replace, or with a quoted pattern and replacement.
Clear note on java / regex. "replaceAll treats input as regex" is the kind of detail that is easy to overlook.
Good to see "replaceAll treats input as regex" written down. Handy reference for anyone working with java / regex.
Clear note on java / regex. "replaceAll treats input as regex" is the kind of detail that is easy to overlook.
Clear note on java / regex. "replaceAll treats input as regex" is the kind of detail that is easy to overlook.