regex - Java string replacing (remove newlines, change $ to \$) -
i have string ($
character surrounded other characters):
a$b c$d e$f
i want string method put \
in front of $
, remove newlines:
a\$bc\$de\$f
i tried doesn't put \
character:
s=s.replaceall("\n","").replaceall("$", "\\$");
$
reserved character in java pattern
s, indicates end of line or end of input.
you need escape replacement... thrice.
try replaceall("\\$", "\\\\\\$")
Comments
Post a Comment