I\'m trying to replace the beginning of a string with backslashes to something else. For some weird reason the replaceAll function doesn\'t like backslashes.
Str
Just got into a similar problem.
If you use backslash() in the second section of the replaceAll function, the backslashes will dissapear, to avoid that, you can use Matcher class.
String assetPath="\Media Database\otherfolder\anotherdeepfolder\finalfolder";
String assetRemovedPath=assetPath.replaceAll("\\\\Media Database(.*)", Matcher.quoteReplacement("\\Media Database\\_ExpiredAssets")+"$1");
system.out.println("ModifiedPath:"+assetRemovedPath);
Prints:
\Media Database\_ExpiredAssets\otherfolder\anotherdeepfolder\finalfolder
hope it helps!