public class ChessMethod {
public static void main(String[] args) {
String line=" 1.d4 Nf6 2.c4 g6 0-1]";
String[] elements = line.split("[\\s.]+");
String first = elements[1];
String[] trailing = Arrays.copyOfRange(elements,1,elements.length);
System.out.println(Arrays.deepToString(trailing));
}
}
Output= [1, d4, Nf6, 2, c4, g6, 0-1]]
I would like to get rid of the "1.","2." part of the move list and only keep the
d4, Nf6... I was going to add them to a list.
Is there a better way to do this with a delimiter? Do I have to make a method that checks the (if there is one) numerical value of every String in my Array, and saves the ones that dont have one?
"\\s*\\d+\\.\\s*"as delimiter, then split on whitespace?