I have a Codefragment that works for every escape except \ the problem i have is that split removes all \
public static String esc = "\\";
public static String[] saveSplit(String str, String regex) {
String[] test = str.split(regex);
ArrayList<String> list = new ArrayList<>();
String storage = "";
for (String string : test) {
if (!endsWith(string, esc)) {
if (!storage.equals("")) {
list.add(storage + string);
storage = "";
continue;
}
list.add(string);
} else {
storage += string.replace(esc, regex);
}
}
if (!storage.equals("")) {
list.add(storage);
}
String[] retArray = new String[list.size()];
retArray = list.toArray(retArray);
return retArray;
}
i need this method to savely split a string that have \ without removing the \ so when i escape the \\
with \\\\
they wont get lost
what i excpect is that String s = "\\\\element1\\element2\\\\\\element3\\\\element4
turns to [{\\element1},{element2},{\\element3\\element4}]
but it removes all \