first divide them into an array by ,, and then apply a regular expression to check if it is in the desired formate or not. If yes, indicate all that are shared,
String abc ="abc_123,low,101.111.111.111,100.254.132.156,abc,1";
String[] split = abc.split(",");
String concat="";
for(String data:split){
boolean matched=data.matches("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}");
if(matched){
concat=concat+","+data;
}else{
System.out.println(data);
}
}
if(concat.length()>0)
System.out.println(concat.substring(1));
}
user4768611
source
share