Try this. I am assuming path
is a real word. This also includes the \
after loading so it would not change paths where loading
would be loadingPlatform
or somewordloading
which may produce undesirable results. Note that the back slashes need to be escape once for the String and once for the regex engine.
String s = "\\path\\test\\files\\loading\\hold\\sample.text";
s = s.replaceAll("\\\\path.*\\\\loading\\\\", "..\\\\");
System.out.println(s);
prints
..\hold\sample.text
0
solved How to get a substring from the beginning till the middle of a word using regex [closed]