My goal is to replace all "/" and "\" with one "\".
Input:
String path = "H\\\\\\\\\\ello///Wo\\rld\\!////";
Output:
String path = "H\ello\Wo\rld\!\";
Question:
Is there a way to do that all in one single line?
My solution (working!):
- change all to the same char
- replace all "/" with one Slash
- put it back to normal
I learned that I need regex and that "[X]+" will put all possible combinations eg. "XXfXfXXXX" to "XfXfX".
I am searching for something like: (pseudocode)
path = path.replaceAll("[\\/]+", "\\");
I tried some combinations of that but everytime it throw errors.
My Solution:
path = path.replace("\\", "/");
path = path.replaceAll("[/]+", "/");
pfad = pfad.replace("/", "\\");