I have String like this: "LODIXAL COMP 15"
How can i split it to "LODIXAL COMP" and "15" ?
String a = "LODIXAL COMP 15";
String[] result = {"LODIXAL COMP" , "15"}
I have String like this: "LODIXAL COMP 15"
How can i split it to "LODIXAL COMP" and "15" ?
String a = "LODIXAL COMP 15";
String[] result = {"LODIXAL COMP" , "15"}
Use this positive lookahead based regex:
a.split(" (?=\\d+)");
TESTING:
System.out.println(Arrays.toString(a.split(" (?=\\d+)")));
OUTPUT:
[LODIXAL COMP, 15]
a.split(" (?=\\d+$)") for that. I can edit the answer but we don't know if OP can have string like that in his/her code.a.split(" (?=X\\s*\\d+)"); for your string "ACEDICON COMP 1 X 5 MG"