String[] parts = msg.split(" +\n?");
String room = parts[0];
System.out.println(msg);
System.out.println("Laczenie do" + room + ", " + parts.length);
for (String s : parts)
System.out.println("-" + s + "-");
output:
main
Laczenie do, 2
--
-main-
What is this first char? How to cut it using regexp?
That is the empty string at the start of the string. Your regex splits on one or more spaces, optionally followed by a newline character. Since your string starts with spaces, the first split occurs around those spaces – the left-hand part is empty, the right-hand part is
mainetc.Visualizing the spaces using
_, your string looks like:So when you split it, it gets divided into the part before
__("") and the part after__("main").What did you expect to happen?