Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to split string contains numbers in java?

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"}
like image 706
michdraft Avatar asked Jan 12 '12 14:01

michdraft


1 Answers

Use this positive lookahead based regex:

a.split(" (?=\\d+)");

TESTING:

System.out.println(Arrays.toString(a.split(" (?=\\d+)")));

OUTPUT:

[LODIXAL COMP, 15]
like image 115
anubhava Avatar answered Sep 21 '22 05:09

anubhava