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("/", "\\");

\with\? It doesn't change anything. Do you perhaps want to replace series of\and/with single\?.replaceAll("[\\\\/]+", "\\\\")if all chunks of 1 or more\and/chars should be replaced with one\.\\\\//? Should it be one\or maybe two\\(one for\\\\sequence and second for//sequence)?