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 patterns, indicates end of line or end of input.

you need escape replacement... thrice.

try replaceall("\\$", "\\\\\\$")


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -