更新时间:2022-11-14 14:23:56
使用 replaceAll
你将不得不使用 .replaceAll("\\\\r", "\r");
因为
With replaceAll
you would have to use .replaceAll("\\\\r", "\r");
because
\
您需要对其进行转义,因此您需要使用 pass \\
到正则表达式引擎 \
创建字符串文字,您需要将其写为 "\\"
.\
in regex you need to escape it so you need to use pass \\
to regex engine \
you need to write it as "\\"
.更清晰的方法是使用 replace("\\r", "\r");
它将自动转义所有正则表达式元字符.
Clearer way would be using replace("\\r", "\r");
which will automatically escape all regex metacharacters.