I have a string having key and value:
A=1,B=2,C=3,D=4,E=5
I need a split regex in java to get these values (1,2,3,4,5) from above string.
You can use regex with this pattern [0-9]+
String toIndex = "A=1,B=2,C=3,D=4,E=5";
Pattern p = Pattern.compile("[0-9]+");
Matcher m = p.matcher(toIndex);
while (m.find()) {
System.out.println(m.group());
}
and in the while instead of printing the groups add then to a list or similar for latter manipulation
A=AA,B=BB,C=CC,D=DD,E=EEuse this:
String s = "A=1,B=2,C=3,D=4,E=5";
Pattern p = Pattern.compile("=(\\d+)");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group(1));
}
\d+ is for one until n digits
A=AA,B=BB,C=CC,D=DD,E=EESince you asked to use split, this will work as well.
String str2 = "A=1,B=2,C=3,D=4,E=5";
String [] between = str2.split("=+|,");
for(int i=1; i<between.length; i+=2){
System.out.println(between[i]);
}
Works for both strings and numbers between = and ,
(A=AA,B=BB,C=CC,D=DD,E=EE)