You can try to split it this way
String[] tokens = "create Person +fname : String, +lname: String, -age:int;"
.split("[\\s:;,]+|(?<=[+\\-])");
//split on set of characters containing spaces:;, OR after + or -.
for (String s : tokens)
System.out.println("=> " + s);
output:
=> create
=> Person
=> +
=> fname
=> String
=> +
=> lname
=> String
=> -
=> age
=> int
As you can see it will put create
at start of your array so just start iterating from tokens[1]
.
You could try do add ^create\\s
as part of splitting rule, but this will produce empty string at start of tokens array, so won't solve anything.